Using custom php.ini in a cPanel server

Recently in our office at YIPL, we needed to increase the upload_max_filesize and post_max_size of one of our clients. We run on a virtual private server with WHM and cPanel.

The default php runs as a FastCGI with suexec enabled.

Here is how I configured apache to run custom php.ini.

1. Know where your existing php.ini file exists.

Just create a phpinfo.php file in your public_html or www folder. Use the phpinfo() function know the current location of default php.ini.

/home/username/public_html/phpinfo.php

<?php
phpinfo();
?>

Access the file with http://www.sitename.com/phpinfo.php.

2. Copy the file inside your cgi-bin folder

$ cp /usr/local/lib/php.ini /home/username/public_html/cgi-bin

3. Create a custom cgi executable to run php.

$ vim /home/username/public_html/php.cgi

Add following lines

#!/bin/sh
/usr/local/cpanel/cgi-sys/php5 -c /home/username/public_html/cgi-bin/
# Note, the parameter after -c is the location of new php.ini

Allow executable permission to the new php executable

$ chmod +x /home/username/public_html/cgi-bin/php.cgi

4. Modify .htaccess to run php with our new executable by adding the following lines at the top

$ head /home/username/public_html/.htaccess
Action application/x-httpd-php5 /cgi-bin/php.cgi

#.. other commands

5. Make sure new configuration is loaded.

The http://www.sitename.com/phpinfo.php file should now show /home/username/public_html/cgi-bin/php.ini as the loaded setting file.

6. Remove phpinfo.php for security purposes

$ rm /home/username/www/phpinfo.php

References

Comments

Hello,

Thank You very much for this tutorial.

I just tried to tweak the .ini file as suggested. I took these steps:

  1. copied the "/usr/local/lib/php.ini" to the "public_html/cgi-bin" directory
  2. created  a custom "php.cgi" executable file, within the "public_html/cgi-bin" folder (chmod 777)
  3. changed the root .htaccess file, with the "action" line at the very top.

Nonetheless, visiting the info.php file it keeps saying "Loaded Configuration File: /usr/local/lib/php.ini" instead of "Loaded Configuration File: /home/[username]/public_html/cgi-bin/php.ini".

Any ideas? Thank You again for sharing your solution.

bye

jcool

 

I cannot comment on your config, but it should work pretty fine without any problem.

Anyways u should change the 777 permission to 744 or 755 since, fcgid doesn't play well with 777 permissions.

See if that helps.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Easily link to terms in various wikis. For help, see <a href="/interwiki/1">interwiki</a>.

More information about formatting options