Enable fopen only for a specific cPanel or linux user with suPHP

For security reasons most hosts will have fopen disabled. This is for security reasons but there are also times when it is legitimately needed. Below I will show you how to enable fopen for a single cPanel user instead of server wide.

This may be the error you get:

or

Here’s how to fix it:

You will need shell access to the server and i’m assuming that you are the server administrator and not just a user on the server. If you are just a user on the server you can just create your own php.ini file in your public_html directory and change the setting explained below.

UPDATE 1/2/2014: 

I recommend using the PHP.ini manager for cPanel/WHM instead of custom files, you can find more information here:

http://how2.be/en/community/phpinimgr/

There’s also great information on the cPanel forum about adding specific entries for specific directories:

http://forums.cpanel.net/f185/methods-increase-security-suphp-restricting-who-can-use-php-ini-files-167186.html

First let’s find out where our PHP.INI file is located at, do so with this command:

You should get an output similar to this:

That tells us that our current loaded PHP.INI file is located at /usr/local/lib/php.ini. We will need this file because we will be creating a copy of it in the users public_html directory.

Change directory into the users public_html folder:

Let’s verify that a PHP.INI does not already exist:

If you do not find a PHP.INI file with the above command, copy the PHP.INI file we just found using this command:

UPDATE: I do not recommend copying the entire file, this could cause issues with references in the php.ini file pointing at old modules, etc.

Recommendation is to just create a new php.ini file and put allow_url_fopen=On in it. Add the suPHP_ConfigPath below and it should work

Now we need to assign the user as the owner and group, do this with chown:

Now we need to add the configpath to the .htaccess file, use this command to add it:

You have now successfully setup a custom PHP.INI file for that specific user.

In order to enable fopen, use nano or your favorite editor and open the php.ini file.

Search for

and change the setting to ON.

Myles

Orlando, FL

Did this post help you?

Give back and rate it for me!

Related Posts