PHP.ini

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

= Determine which PHP Version your website uses =

There are different methods to customize PHP, based upon which version you use:


 * PHP 5.4 - The newest version, has an all-new and easy way to customize the settings (e.g., Runtime Configuration, phprc, and so on).
 * PHP 5.3 - A very common version, has an all-new and easy way to customize the settings (e.g., Runtime Configuration, phprc, and so on).
 * PHP 5.2 or older versions - A lot harder to customize, no longer being developed, and eventually will no longer be supported at DreamHost.

Your website may require a specific PHP version. Some PHP modules exist for 5.2 but not 5.3, such as Zend Optimizer. Some plugins or other parts of your website application may only work with a specific PHP version.

You can check which version of PHP your website is using from your DreamHost panel (on the Manage Domains page):
 * 1) Click Edit to view the hosting settings and check the PHP mode setting.
 * 2) Set it to PHP 5.3 (FastCGI) if you can, or 5.2 if you need to use the older version.

Adding global custom changes (VPS or Dedicated ONLY)
If you have:


 * a VPS or dedicated server and want to customize php.ini for the entire server, and
 * you don't want to manage PHP yourself

Then you can add any values you'd like to customize to the following file (similar to the phprc method below) using your admin user and sudo.


 * For PHP 5.4 changes, make/edit the file:
 * /etc/php54/php.ini


 * For PHP 5.3 changes, make/edit the file:
 * /etc/php53/php.ini


 * For PHP 5.2 changes, make/edit the file:
 * /etc/php5/cgi/php.ini


 * NOTE: (8/6/13 - If you're running in mod_php mode, you should make/edit the file /etc/php5/php.ini)

Once you've made/edited that file, simply end all active PHP processes, and it should work.

Note: If you're on NGINX, you must stop NGINX before killing PHP, then restart it. sudo /etc/init.d/nginx stop pkill -9 php sudo /etc/init.d/nginx start

= PHP 5.3 / 5.4 =

phprc
Setting up a phprc file that is used by all the sites hosted under a user is easy to do.

To setup a phprc file, start by creating the folders for the custom settings file using the shell or an FTP program.


 * 1) Create a new folder named .php in your user's home directory /home/USERNAME/.
 * Note: This folder name starts with a '.' or dot, and if you're using an FTP program you may need to turn on "view hidden files and folders" to see it after you create it (for more information about that check out FTP.
 * 1) Inside that create another folder based on what version of PHP you're using (either 5.3 or 5.4).
 * The shell command for 5.3 is:
 * mkdir -p ~/.php/5.3
 * The shell command for 5.4 is:
 * mkdir -p ~/.php/5.4
 * 1) Inside all those folders, /home/USERNAME/.php/PHP_VERSION_NUM/, create a new text file named phprc.
 * Note: Make sure that's the exact name, with no file extension. This phprc file is where you will put all your custom PHP settings.

phprc and php.ini
Anything set in both phprc and php.ini:


 * uses the phprc values, while
 * everything else uses the values set in php.ini.

It's an easy way to change what you want and ignore the rest.

You can also:


 * use different phprcs for each domain.
 * use a phprc to test out new configurations and eventually move them to php.ini.
 * edit php.ini directly.

Replacing the system php.ini entirely
To replace the system php.ini entirely:
 * 1) Create a file under  (or  ) named   (make sure you know which version of PHP you're working with).
 * Note: If this file exists, PHP will not read the system php.ini at all, so you should probably start by copying  or   as a starting point. In most cases, this file is not necessary. Please use a   if at all possible.

Force PHP to reload
If needed, force PHP to reload its configuration file for changes to take effect using the following shell code, or by waiting several minutes.


 * killall php53.cgi or killall php54.cgi

= PHP 5.2 =

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. Also, PHP 5.2 is no longer supported by PHP.

You can still find instructions on how to edit your php.ini under 5.2 here: Editing php.ini for 5.2

<!--

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.

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. <li>Upload it to the /home/yourusername/example.com/cgi-bin directory. </ol>
 * 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</tt>.

If you do not see the file, perform the following to create: <ol> <li>Create a text file in the root and name it .htaccess. <li>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 </Pre> </ol> 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.

<ul> <li>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 $* <li>Open the DreamHost admin panel and ensure that your domain has FastCGI support? enabled. <li>If all else fails: <ol> <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.

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.

<ol> <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.

-->

= Custom php.ini for nginx servers =

The following are instructions and tips to tweak your php settings or xcache settings on nginx.

Custom Global php.ini commands on Nginx

 * To completely replace DH default php config file for all your domains under a particular user, create a file .php.ini in your home:
 * /home/madamimadam/.php-ini
 * Note: If you compiled a custom binary, you can use .php-launcher to specify that as well, though unlikely since DH is on PHP 5 now.
 * To change what wasn't meeting your needs, we recommend you start by copying the configuration in use :
 * cp /etc/php5/cgi/php.ini ~/.php-ini

Custom php.ini commands per domain on Nginx
Since nginx runs an instance of PHP for each user, you can't specify php settings at a domain level.

However, because each user gets their own instance, you can create specific configurations for specific domains or groups of domains by migrating those sites under a different user:

madamimadam --> www.domain1.com --> www.domain2.com hannah --> www.domain3.com --> www.dmoain4.com

Notes:
 * This makes maintenance a bit more segregated, but you can still use a single user for all your cron jobs, backup operations, and so on. The new users are nothing more than "groupings" for configuration specific domains.
 * There are now two instances of PHP running instead of one, so your memory consumption increases.

Reloading Nginx
You can reload then Nginx web server to view new files (requires admin / sudo user):

sudo /etc/init.d/nginx restart

Note: If you receive a 504 timeout, then kill and restart PHP.

= I modified the existing php.ini/phprc, but I'm not seeing the changes? =

Here a few suggestions:


 * See the FastCGI page for instructions on how to either restart FastCGI or force a recache.
 * To restart PHP 5.2 FastCGI from the shell:
 * killall -9 php5.cgi
 * For PHP 5.3:
 * killall -9 php53.cgi
 * For PHP 5.4:
 * killall -9 php54.cgi
 * If you are using PHP 5.2 with a PHP wrapper, the following may also be necessary:
 * touch $HOME/example.com/cgi-bin/php-wrapper.fcgi

= Errors when using Apache mod_rewrite =

If you're receiving an error while using mod_rewrite on your website(s), you must add the following line to your .htaccess (after "RewriteEngine on"):

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

= How to Customize your Settings =

Now that you've got a custom php.ini (or phprc), you can make some suggested changes to customize how things run.

Note: 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.

Error Logging
Enabling PHP error logging is a simple step that allows easier diagnosis of problems with your website:

To enable:

<ol> <li>Add these lines to your php.ini</tt> or phprc</tt>: log_errors = 1 error_log = /home/USERNAME/php.log <li>Replace USERNAME with your server user.

<li>You may need to force PHP to reload its configuration file for changes to take effect using the following shell code, or by waiting several minutes. killall php53.cgi or killall php54.cgi </ol>

Increasing the Filesize Upload Limit
The default size limit for uploading files is 7MB, which may be far too small for your needs.

To increase that limit to 64MB, use the following command:

upload_max_filesize = 64M post_max_size = 64M max_execution_time = 500 max_input_time = 500

Increasing the PHP Memory Limit
The default memory limit is 90M and this is usually more than sufficient for most needs.

If you wish to increase this limit, you'll want to use the following:

memory_limit = 128M

Using PHP Loaders (Zend Optimizer, IonCube Loader, and so on)
PHP Loaders are extensions to PHP to load special types of PHP files. You must modify your php.ini</tt> or phprc</tt> to activate the loader required by your special PHP files.

Below are links to pages that provide further instructions on installing and using the various PHP loaders:


 * General Instructions for Installing PHP Loaders
 * IonCube Loader
 * ZendGuard_Loader

Loading PHP 5.3 Extensions
The current DreamHost build of PHP 5.3 contains a number of additional extensions which are not loaded by default (for example, soap).


 * 1) To load, add the following line to a file at :
 * extension = soap.so
 * 1) Create the path/file for phprc if not present.
 * 2) Restart the server when finished.

Loading PHP 5.3 extensions on all domains (on VPS or dedicated)
On a DreamHost VPS or dedicated server, you can also create the directory. Any files in this directory are loaded by all PHP 5.3 interpreters in addition to the default file,.


 * 1) Create a root/admin user and log in.
 * 2) Upload your file to your FTP server.
 * 3) Through shell, copy the files into the /etc/php53/conf.d/ directory:
 * sudo cp filename /etc/php53/conf.d/
 * 1) When prompted by the machine, enter your admin user password.

Compiling PHP 5.3 extensions
To compile and load your own extensions:


 * 1) Download and unpack the extension (from PECL, for example).
 * 2) If the extension is already compiled (most binary PHP loaders are already compiled), skip to step 4.
 * 3) Enter the following commands:
 * /usr/local/php53/bin/phpize
 * ./configure --with-php-config=/usr/local/php53/bin/php-config
 * make
 * 1) Copy the module to your  directory.
 * 2) Assuming your user is called " " and your module is named " ", add the following to your : extension = /home/username/.php/5.3/mymodule.so

Your new extension is now enabled, and is loaded by all domains using PHP 5.3 under that user.

= See also =
 * Installing PHP5
 * Installing PHP4
 * Advanced PHP configuration

= 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)