Back to PHP (Applications and Scripts)

How To Set Up Custom PHP Settings

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 jail shell will need to be enabled on your account. Putty can be downloaded from, 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 it 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 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 it with your cPanel username.  This line of code would make the php configuration values in your public_html/php.ini file apply to all subdirectories 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 about configuring these files.

Related Articles

How To Troubleshoot PHP Upgrade Issues
Can I Enable PHP Allow_url_include On My Account
Can I Increase The PHP post_max_size Setting
Can I Modify My Suhosin Settings With A Local php.ini File
Can I Utilize PHP Shell Exec Functions

Can’t Find what you need?

No worries, Our experts are here to help.