Search

How do I setup custom php.ini settings?

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 by simply contacting support and requesting it.

As many of you know we have our shared hosting servers to 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 the following permissions:

644 permissions with the owner cpanelusername:cpanelusername

Lets 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 /usr/local/lib/php.ini ./

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:

SetEnv PHPRC /home/USERNAME/public_html/php.ini

Where USERNAME is replaced 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 (support@midphase.com) if you have any questions with configuring these files.
Last Updated: 25th of May, 2011     Article ID: 34

Continue