How to create a custom php.ini file when nothing else works
A client of ours was having trouble recently when uploading files to their Drupal site. Their webhost had set values in the default php.ini file too low (a common limitation of shared hosting), and we needed to increase the upload_max_filesize and post_max_size values. This account was limited more than most and overriding the php.ini defaults the usual way (by adding various lines to the .htaccess or settings.php files) didn’t work at all.
If you’ve had the same experience, you may find that the following steps work for you.
This tutorial was added to the Drupal handbook in May, 2007. No Drupal modules are needed, but the Devel module certainly helps.
1. Get and modify your custom php.ini file
It’s best to use a php.ini file that somewhat resembles the one already running on your server. You can find your server’s active php.ini file by running phpinfo() (this function is available in the Devel module)and copying it into your account directory (you do not need to put it in your worldly-readable directory such as “public_html” or “www” or “htdocs” — you know the one).
Edit your new php.ini file and save your changes. I needed to change the upload_max_filesize and post_max_size values, but checked register_globals and changed memory_limit and max_execution_timeout while I was at it. There are handbook pages on increasing memory and upload size if you need help with the syntax.
2. Create a CGI script
Now create a small script and put it in your cgi-bin directory. In your web folder, create another folder called “cgi-bin” if it’s not there already. Using your preferred text editor, create a file name “php.cgi” and put the following into it:
exec /usr/local/cpanel/cgi-sys/php5 -c /path/to/drupal/
If you don’t have cPanel on your account, try /etc/php5 instead. In any case, replace the /path/to/drupal/ part with the full path to your Drupal installation, such as /home/youraccount/public_html/ or /home/youraccount/public_html/drupal/
Since this is a script that needs to run as an executable file, use the chmod command and type this at the command line:
Don’t have shell access? That’s outside the scope of this tutorial, but you can use an FTP program that can change permissions of files, ask your webhost to make the php.cgi script executable for you, or make it executable with some PHP code (perhaps with the devel module’s Execute PHP block).
3. Modify the .htaccess file
Add this one line to your .htaccess file:
This tells Apache to perform an action each time it encounters a file of file type “application/x-httpd-php5” — if you’re using a version of PHP older than PHP5, you’ll need to change this to “application/x-httpd-php” (or upgrade to PHP5 — ask your webhost).
4. Test your site
Load up your website and see if it works. If it does, good job! If it doesn’t, go back to step 2 or 3 and check to see what version of PHP your site is using. You can also ask your webhost for help.
If you increased your post_max_size or upload_max_size, then look at your admin/settings/uploads admin page and see how big your uploads can be. If you increased your memory_limit, check phpinfo or devel module’s phpinfo() page at admin/logs/status/php