Overriding PHP settings with PHP in CGI mode
Submitted by Bram Schoenmakers on 25 October, 2007 - 11:42.
On a webserver where suexec is active, each website has it's own php-cgi wrapper. The contents are quite simple:
#!/bin/sh
exec /usr/local/bin/php-cgi
exec /usr/local/bin/php-cgi
Unfortunately, since PHP runs in CGI mode and not as an Apache module, overriding PHP settings is not possible within a .htaccess file. But there's another way of doing this.
The php-cgi binary is aware of the $PHPRC environment variable, which points to a directory containing an alternate php.ini file. So we add a new line to the wrapper, prior to the exec call:
export PHPRC="~somewebsiteuser/cgi-bin/"
Make sure you don't point to the php.ini file itself, but to the directory containing it.
Now you can create a php.ini file in the specified directory and override some settings. This page shows which settings you can override, those with PHP_INI_PERDIR.