PHP.ini

From DreamHost

Jump to: navigation, search
The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.
Server changes may cause this to break. Be prepared to troubleshoot this yourself if this happens.
We seriously aren't kidding about this. Read the blinky part again.

Below are instructions for using your own modified version of php.ini on a domain called "example.com". DreamHost technical support does not recommend, and will provide no support for this method. Follow these instructions at your own risk.

Contents

Set up your domain for FastCGI

These instructions work for "PHP 5 FastCGI" selection at domain management page. If you face with seeing only php-wrapper.ini contents, thats because you didn't choose this option.

Custom php.ini for a Single domain

Create a cgi-bin folder for your domain

mkdir $HOME/example.com/cgi-bin

Copy the default php.ini file

cp /etc/php5/cgi/php.ini $HOME/example.com/cgi-bin/php.ini

Make modifications to this file as necessary. Note that 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.

Create the script wrapper

cat << EOF > $HOME/example.com/cgi-bin/php-wrapper.fcgi
#!/bin/sh
exec /dh/cgi-system/php5.cgi $*
EOF

Alternate method

Since many seem to have a problem with this step, here is an alternate way to Create the script wrapper: Just 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:

#!/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.

Set 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

Set up the .htaccess file

The .htaccess file is located in your document root at $HOME/example.com/.htaccess. If you do not yet have one, you can create a text file there and name it .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.fcgi
Action php5-cgi /cgi-bin/php-wrapper.fcgi

Please note that as with the text file you created for the script wrapper, the text editor you use 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.

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

Done everything and it still doesn't work?

If you've done everything but you just 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) as follows.

Add the following after the first line:

export PHPRC=/home/yourusername/example.com/cgi-bin

Result:

#!/bin/sh
export PHPRC=/home/yourusername/example.com/cgi-bin
exec /dh/cgi-system/php5.cgi $*

Done that and it STILL doesn't work?

Go into the Dreamhost admin panel and ensure that your domain has "FastCGI support?" ticked. May sound obvious but had me puzzled for half an hour!

Custom php.ini across Multiple domains

The steps below are essentially the same as above but only create one cgi-bin folder that is shared across multiple domains.

Create a cgi-bin folder in your Home directory

 mkdir $HOME/cgi-bin

Copy the default php.ini file

 cp /etc/php5/cgi/php.ini $HOME/cgi-bin/php.ini

Make modifications to this file as necessary. Note that 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.

Create the script wrapper

Create a text file in the cgi-bin directory that you created above (/home/yourusername/cgi-bin) named php-wrapper.fcgi, 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, and then upload it to the /home/yourusername/cgi-bin directory.

Set permissions

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

Repeating Steps

These two (2) steps must be done for, and within each domain or sub-domain you wish to leverage the custom php.ini. Any domains that do not use these steps will remain on DreamHost's global php.ini.

Create a Soft Link to your central cgi-bin

ln -s /home/USERNAME/cgi-bin/ /home/USERNAME/webroot/NEW.DOMAIN.com/cgi-bin

I use a webroot folder to coral all of my domains, in your case it might instead be;

ln -s /home/USERNAME/cgi-bin/ /home/USERNAME/NEW.DOMAIN.com/cgi-bin

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.fcgi
 Action php5-cgi /cgi-bin/php-wrapper.fcgi

You can now modify $HOME/cgi-bin/php.ini to your heart's content!

Modified existing php.ini but not seeing the changes?

See the FastCGI page for instructions on how to either restart FastCGI or force a recache.

Restarting FastCGI from the shell:

killall -9 php5.cgi

Force a recache:

touch $HOME/example.com/cgi-bin/php-wrapper.fcgi

Apache mod_rewrite

For those who are getting an error while uses mod_rewrite on your websites, you must add the follow line to your .htaccess: After "RewriteEngine on"

RewriteCond %{REQUEST_URI} !^/cgi-bin/.*

See also

External links

Personal tools