Page tree
Skip to end of metadata
Go to start of metadata

This article is for cPanel Accounts. Determine where your account is with this guide.

Accounts in the cPanel shared may have trouble with local php.ini settings because you cannot change the server php.ini and using local php.ini files is not recursive by default.

 

Please note that much of what is described here is best accomplished through the command line. For this you will need an SSH client, such as putty, and jailshell will need to be enabled on your account. Putty can be downloaded from http://www.chiark.greenend.org.uk/~sgtatham/putty/, and jailshell can be enabled on your account simply by contacting support and requesting it.
 

As many of you know, we have our shared hosting servers running php 5 with phpSuExec enabled.  Because of this configuration, users are not able to have php flags in their .htaccess file. Having php flags in .htaccess files is a common cause of internal server errors on servers with phpSuExec enabled. One way around this is to create a custom php.ini file with the php values you need.
 

This file should have 644 permissions with the owner cpanelusername:cpanelusername
 

Let’s assume your cpanel username is bobbob1. Your php.ini file should look like this in your file manager or ftp client:

-rw-r--r--   1 bobbob1 bobbob1  21 Nov 20 18:57 php.ini


While you can simply create a blank php.ini file, and then enter the values you need to override, there are security concerns with this method. Php will revert to an absolute base configuration, which means some applications may throw a fit because certain extensions aren't enabled. A way around this is to copy the system php.ini. This can be accomplished through jailshell using the following command:

cp /opt/cpanel/ea-php56/root/etc/php.d/local.ini > /home/USERNAME/public_html/php.ini


Where
USERNAME is stated, please replace with your cPanel username. This command will copy the file into the directory you are currently in (if you just logged in, it's most likely your home directory).
 

Now that you have created your php.ini file, you can populate it with the php configuration values you need to override on the server.
 

The syntax generally follows this format:

phpconfigValueToOverride = value


For example, say the server default for upload_max_filesize is 2M (megabytes).  You can override this value by creating your own php.ini file and entering a line like this:

upload_max_filesize = 10M


This would set the new php upload limit to 10 megabytes.
 

Other common configuration changes include: upload_tmp_dir, display_errors, session.save_path, etc...
 

You can check your current php settings by using the phpinfo() function. Simply place phpinfo(); in a new file with a .php extension.
 

Generally, when you create custom php.ini the changes will only have an effect on the scripts in the same directory. This can be changed by making the php.ini apply recursively. This is accomplished by entering the following code into a .htaccess file:

#Use local php.ini file recursively from public_html
SetEnv PHP_INI_SCAN_DIR /opt/cpanel/ea-php56/root/etc/php.d/:/home/USERNAME/public_html/


As before, where
USERNAME is stated, please replace with your cPanel username.  This line of code would make the php configuration values in your public_html/php.ini file apply to all sub directories of where you place the .htaccess file.
 

The most common setup is to place your custom php.ini at public_html/php.ini, and then place the .htaccess file at public_html/.htaccess.


Please feel free to contact our support department if you have any questions on configuring these files.