PHP.ini
From DreamHost
| The instructions provided in this article or section are considered advanced. You are expected to be knowledgeable in the UNIX shell. |
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!
Custom PHP.ini for nginx servers
So you are using super fast nginx on your PS server ay? Smart lad (or lass). But if you want to tweak your php settings, or xcache settings on nginx, then read on!
Custom Global php.ini on Nginx
To completely replace DH default php config file for all yer domains *under a particular user* just create a file .php.ini in your home.
/home/madamimadam/.php-ini
(if you compiled a custom binary you can use .php-launcher to specify that as well - unlikely since DH is on php5 now. )
I recommend you start by copying the configuration in use and just change what wasn't meeting your needs.
cp /etc/php5/cgi/php.ini ~/.php-ini
Custom php.ini per domain on Nginx
now because nginx runs an instance of PHP for each user, you can't specify php settings at a domain level.
BUT!
Because each user gets their own instance - you can create specific configurations for specific domains or groups of domain by migrating those sites under a different user.
madamimadam --> www.domain1.com --> www.domain2.com hannah --> www.domain3.com --> www.dmoain4.com
Now admittedly this will make maintenance a bit more segregated, but you can still use a single user for all your cron jobs and backup operations etc. So the new users are nothing more that "groupings" for configuration specific domains. Also there will be 2 instances of PHP running instead of 1, so your memory consumption will rise.
Thanks Andrew F!
Reload Nginx
we can knowz about the new files by reloading Nginx web server (requires admin / sudo user)
#/etc/init.d/nginx restart
NOTE: This restart gooeyed up my php - support resolved the 504 timeouts by killing php and restarting it.
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/.*

