Knowledgebase: PHP and Apache
Use a Custom PHP.ini File
Posted by on 21 January 2014 11:40 PM

There are several instances that may require you to modify a setting in the php.ini file for your website, such as increasing the PHP upload limit. We definitely permit the use of a custom php.ini file, but there are some requirements involved just to ensure that the files work as expected.

Why create a custom php.ini file?

Some examples of what may be changed by using a custom php.ini file are:

  • Editing the maximum size of a file that can be uploaded in a PHP script (upload_max_filesize = 10M)

  • Editing the maximum PHP post size which must at least match upload_max_filesize (post_max_size = 10M)

  • Editing the maximum file execution time in seconds (max_execution_time = 30)

Discover the Handler

Before a custom PHP directive can be set, the PHP handler needs to be determined, so that the correct method can be used. To find out your PHP handler:

  1. Log into shell as root

  2. Check the file '/etc/httpd/conf/php.conf'

    If you see the line 'LoadModule suphp_module modules/' then you are using suPHP.
    If you see the line 'LoadModule php5_module modules/' then you are not using suPHP, and can use the DSO instructions.

    Please see each set of instructions below.

Create Custom PHP.ini with suPHP

To begin creating your very own custom php.ini file:

  1. Copy your php.ini file in your cPanel user home directory, 'cp /usr/local/lib/php.ini /home/user/' (where 'user' is your cPanel username)

  2. Create a .htaccess file inside the 'public_html' directory of your site OR edit the existing .htaccess file, if one exists, by adding the following line:

    suPHP_ConfigPath /home/user

    Note: you do not need to add 'php.ini' to the end of it. 

Once you have completed the above steps your php.ini file will be active. You will now be able to make edits to the custom php.ini. Your edits will only affect directories below the .htaccess file in which you referenced the file.

Create Custom PHP.ini with DSO

On the DSO server, directives should be placed in the .htaccess file for the directory to which they should apply. In most cases, this will be '/home/USER/public_html/ where USER is your cPanel username.

To edit a boolean value (on/off) you can use php_flag like this:

php_flag magic_quotes_gpc off

To edit a numeric value you can use php_value like this:

php_value memory_limit 256M

Should you require any further assistance with creating a custom php.ini file then check in with one of our fantastic Support people.

See also Override PHP SettingsUse Alternate PHP Installs

(0 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
Full Name:
Help Desk Software by Kayako fusion