I recently needed to increase the memory_limit, upload_max_filesize and post_max_size values to something higher than the measly amount set by a particular webhost's default php.ini file. This account had cPanel on it 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 this how-to works for you.
This how-to is for any version of Drupal running on Linux and Apache. 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 probably find one at /usr/local/lib/php.ini or /usr/local/Zend/etc/php.ini and just copy it into your account's web folder (it may be called "public_html" or "www" or "htdocs" or something -- you know the one).
2. Creating your 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:
#!/bin/sh
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:
chmod -x php.cgi
Don't have shell access? You're on your own, but you can always or the devel module's Execute PHP block, use an FTP program that can change permissions of files, or ask your webhost to make the php.cgi script executable for you.
3. Modifying your .htaccess file
Add this one line to your .htaccess file:
Action application/x-httpd-php5 /cgi-bin/php.cgi
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"
Finally, scroll down to the part that says "# Protect files and directories from prying eyes." and add "ini|" to the <FilesMatch> directive so it looks something like:
<FilesMatch "(\.(ini|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.p hp)?|xtmpl)|code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>
Notice the "ini|" on the first line? This will prevent your custom php.ini file (and anything else ending in .ini) from being accessible to the entire world.
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 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
Comments
Using a custum php.ini with server php.ini
See: http://tips-scripts.com/php_ini
Great post, the most
Great post, the most conclusive guide around and the only thing that worked. Cheers :D