Using Custom php.ini with PHP5 under FastCGI

When using FastCGI (FCGI) as the loader for PHP, traditional php_values in the .htaccess file as well as custom php.ini files in the public_html directory no longer work. Instead we must create a wrapper for the main FCGI binary that causes the php.ini to be loaded from it's current working directory instead of the server-wide one.

First open .htaccess for the account in question and add the following lines to the bottom of the file:

AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php5.fcgi

Next, you'll need to source your main server php.ini which is located in /usr/local/lib/. Also note that it needs to have the correct ownership so we'll take care of that too:

cd /home/user/public_html/cgi-bin/
cp -a /usr/local/lib/php.ini .
chown user:user php.ini

Next we need to create the wrapper script. Create a file in your current directory (cgi-bin) called php5.fcgi as defined above and add the following:

exec /usr/local/cpanel/cgi-sys/php5

Finally, make sure the ownership and permissions are correct on this file:

chown user:user php5.fcgi && chmod 0755 php5.fcgi

You can now edit the php.ini inside cgi-bin/ and change the desired values. You can verify they are set properly by inserting the phpinfo() function inside a PHP script on that user account.