How to create a custom PHP.ini for my Dreamhost hosting account?

Question:
How do I create a custom PHP.ini for my Dreamhost hosting account? I need to modify the maximum upload file size allowed.

Answer:
Here are the steps to create a custom php.ini for a Single domain:

First of all, make sure you are able to log into SSH on your Dreamhost account (see detailed instruction to enable SSH on your account.) Then open Terminal (OS X) or Putty (Windows), and login into your hosting account:
ssh username@domainname.com
password: [type in your account’s admin password]

1. Once logged in, create a cgi-bin folder for your domain:
mkdir $HOME/example.com/cgi-bin

2. Copy the default php.ini file:
cp /etc/php5/cgi/php.ini $HOME/example.com/cgi-bin/php.ini

3. Create the script wrapper:
Create a text file in the cgi-bin directory that you created above (/home/yourusername/example.com/cgi-bin) named php-wrapper.cgi, containing the following lines:
#!/bin/sh
exec /dh/cgi-system/php5.cgi $*

You can do this with any linux text editor (nano, vi, vim, etc.) in the shell. You can also create this file using your own computer and a *text editor* (not a word processor). Make sure your editor can save the file with unix-style line endings (otherwise the #!/bin/sh line will cause an error!), and then upload it to the /home/yourusername/example.com/cgi-bin directory.

4. Set permissions:
chmod 755 $HOME/example.com/cgi-bin
chmod 755 $HOME/example.com/cgi-bin/php-wrapper.cgi
chmod 640 $HOME/example.com/cgi-bin/php.ini

5. Set up the .htaccess file:
The .htaccess file is located in your document root at $HOME/example.com/.htaccess.

Add this to run .php files with your custom PHP wrapper:
Options +ExecCGI
AddHandler php5-cgi .php
Action php-cgi /cgi-bin/php-wrapper.cgi
Action php5-cgi /cgi-bin/php-wrapper.cgi

6. You can now modify $HOME/example.com/cgi-bin/php.ini to your heart’s content!

Example:
; Maximum allowed size for uploaded files.
upload_max_filesize = 90M
; Maximum size of POST data that PHP will accept.
post_max_size = 100M

Note: some variables (in particular, post_max_size and upload_max_filesize) are subject to internal limitations; increasing them significantly beyond the default values will not work correctly.

Original solution posted at http://wiki.dreamhost.com/index.php/PHP.ini#Custom_php.ini_for_a_Single_domain

To custom php.ini across Multiple domains, see detailed instruction here: http://wiki.dreamhost.com/index.php/PHP.ini#Custom_php.ini_across_Multiple_domains

Advertisements
%d bloggers like this: