Editing php.ini for 5.2

Below are instructions for using your own modified version of php.ini on a domain called "example.com".

PHP 5.2 is considerably harder to configure than PHP 5.3 (and 5.4). DreamHost recommends that all users needing custom PHP setup use PHP 5.3 or later, as the configuration changes required to set it up are much simpler and eventually will no longer be supported at DreamHost.

SXi's Easy Auto Copy Script
Run the php script to override your php.ini using the DreamHost Custom PHP.INI auto-installer. With SXi, you no longer need to hassle with SSH or edit htaccess files.

Set up your domain for FastCGI
These instructions work when you select PHP 5 FastCG on the domain management page. If you only see php-wrapper.ini contents, then PHP 5 FastCG is not selected.

Important: Before you begin, we highly recommend that you copy ALL the commands that are needed to a text editor and perform the changes before you enter them via SSH.

Creating a cgi-bin folder for your domain
mkdir $HOME/example.com/cgi-bin

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

Note: Make modifications to this file as necessary. Some variables (in particular,,   and  ) are subject to internal limitations; increasing them significantly beyond the default values will not work correctly and will cause issues with your site.

Creating the script wrapper
cat << EOF > $HOME/example.com/cgi-bin/php-wrapper.fcgi exec /dh/cgi-system/php5.cgi \$* EOF
 * 1) !/bin/sh

Alternate method to create the script wrapper
If you are having problems creating the script wrapper, here is an alternate way:  Create a text file in the cgi-bin directory that you created above (/home/yourusername/example.com/cgi-bin) named php-wrapper.fcgi, containing the following lines: exec /dh/cgi-system/php5.cgi $* Note: You can do this with any linux text editor (nano, vi, vim, etc.) in the shell, or you can 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. Upload it to the /home/yourusername/example.com/cgi-bin directory. 
 * 1) !/bin/sh

DreamHost script from SXi (lazy method)
Edit your own php.ini on DreamHost.

To use, install the dh-phpini.php into the domain root folder.

Notes:
 * Installation runtime ~ 1 sec.
 * Works on x86, x86-64, Sarge, Etch, and VPS servers.
 * Your editable php.ini will be created in the domain's cgi-bin folder.

Setting permissions
chmod 755 $HOME/example.com/cgi-bin chmod 755 $HOME/example.com/cgi-bin/php-wrapper.fcgi chmod 640 $HOME/example.com/cgi-bin/php.ini

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

If you do not see the file, perform the following to create:  Create a text file in the root and name it .htaccess. Add the following to run .php files with your custom PHP wrapper: Options +ExecCGI AddHandler php5-cgi .php Action php-cgi /cgi-bin/php-wrapper.fcgi Action php5-cgi /cgi-bin/php-wrapper.fcgi   You can now modify $HOME/example.com/cgi-bin/php.ini as needed.

Note: As with the text file you created for the script wrapper, the text editor you used to create or edit your .htaccess file should support unix-style line endings; otherwise you may get an Internal Server Error when you visit your site.

If you've done everything and it still doesn't work
The following are tips and suggestions to help you resolve persistent PHP.ini issues.

 If you can't get PHP to load the custom php.ini file, you may want to edit your php-wrapper.fcgi (in $HOME/example.com/cgi-bin). Add the following after the first line: export PHPRC=/home/yourusername/example.com/cgi-bin
 * Result:

export PHPRC=/home/yourusername/example.com/cgi-bin exec /dh/cgi-system/php5.cgi $* Open the DreamHost admin panel and ensure that your domain has FastCGI support? enabled. If all else fails:  <li>Remove everything from your cgi-bin folder. <li>Revert all the changes you made to your .htacces file. <li>Copy the ini file: cp /etc/php5/cgi/php.ini $HOME/example.com/cgi-bin/php.ini <li>Copy the cgi file: cp /dh/cgi-system/php5.cgi $HOME/example.com/cgi-bin/php5.cgi <li>Add the following to the top of your .htaccess file: Options +ExecCGI AddHandler php-cgi .php Action php-cgi /cgi-bin/php5.cgi <FilesMatch "^php5?\.(ini|cgi)$"> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </FilesMatch> </ol> </ul>
 * 1) !/bin/sh

Custom php.ini commands for Multiple domains
The steps below are essentially the same as for a single domain but only create one cgi-bin folder that is shared across multiple domains.

Creating a cgi-bin folder in your Home directory
mkdir $HOME/cgi-bin

Copying the default php.ini file
cp /etc/php5/cgi/php.ini $HOME/cgi-bin/php.ini

Note: You can make modifications to this file as necessary. Some variables (in particular,,   and  ) are subject to internal limitations; increasing them significantly beyond the default values will not work correctly and will cause issues with your sites.

Creating the script wrapper
You can reate a text file in the cgi-bin directory that you created above (/home/yourusername/cgi-bin) named php-wrapper.fcgi, containing the following lines: exec /dh/cgi-system/php5.cgi $*
 * 1) !/bin/sh

Note: 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, and then upload it to the /home/yourusername/cgi-bin directory.

Setting permissions
chmod 755 $HOME/cgi-bin chmod 755 $HOME/cgi-bin/php-wrapper.fcgi chmod 640 $HOME/cgi-bin/php.ini

Leveraging the custom php.ini
You must perform these two steps within each domain or sub-domain you wish to leverage the custom php.ini.

Important: Any domains that do not use these steps will remain on DreamHost's global php.ini.

 <li>Create a Soft Link to your central cgi-bin. ln -s /home/USERNAME/cgi-bin/ /home/USERNAME/webroot/NEW.DOMAIN.com/cgi-bin Note: You can use a webroot folder to coral all of your domains, which might look like this:'' ln -s /home/USERNAME/cgi-bin/ /home/USERNAME/NEW.DOMAIN.com/cgi-bin <li>Set up the .htaccess file by adding the following to run .php files with your custom PHP wrapper:</li> Note: The .htaccess file is located in your document root at $HOME/example.com/.htaccess</tt>. Options +ExecCGI AddHandler php5-cgi .php Action php-cgi /cgi-bin/php-wrapper.fcgi Action php5-cgi /cgi-bin/php-wrapper.fcgi </ol> You can now modify $HOME/cgi-bin/php.ini as needed.

= See also =
 * PHP.ini

= External links =
 * PHP: php.ini directives - Manual (from php.net)
 * PHP: Runtime Configuration - Manual (from php.net)
 * PHP: How to change configuration settings - Manual (from php.net)