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