|The instructions provided in this article or section are considered advanced.|
You are expected to be knowledgeable in the UNIX shell.
- 1 Overview
- 2 Determine which PHP Version your website uses
- 3 How to add a phprc file
- 4 Customization Options
- 5 Adding global custom changes (VPS or Dedicated ONLY)
- 6 Nginx
- 7 External links
Below are instructions for using your own modified version of php.ini on a domain called "example.com".
A php.ini file is a simple text file that allows you to adjust your PHP settings. For example, the server comes with a few default settings such as a PHP memory_limit of 90MB. Other limits that are often changed are for PHP execution time and the PHP max_upload_size. This wiki walks you through how to set up a php.ini (phprc) file and add your custom adjustments.
|Note:||The standard term for this file is php.ini. However, as of PHP 5.3, DreamHost uses a "phprc" file instead. This acts the same way – only the name is different. In this wiki, we’ll use the term phprc.|
Determine which PHP Version your website uses
Before you create a phprc file, you’ll need to know which version of PHP your site is running. The PHP version for each site is displayed in the DreamHost panel on the (Panel > ‘Domains’ > ‘Manage Domains’) page.
- You’ll see the version assigned to any domain to the right under the "Web Hosting" column:
DreamHost pre-installs various versions of PHP on its servers. Here is the listing of PHP versions provided by DreamHost:
- PHP 5.6 ndash; The latest version of PHP that DreamHost has to offer. Allows for settings to be customized in the same way as PHP 5.3 through 5.5.
- PHP 5.5 ndash; A widely supported version of PHP.
- PHP 5.4 ndash; DreamHost’s default PHP version. Also a widely supported version of PHP.
- PHP 5.3 ndash; Officially End-Of-Lifed by php.net as of August 14th, 2014. A widely supported version of PHP which introduces a new and easy way to customize the settings (e.g., Runtime Configuration, phprc, and so on).
- PHP 5.2 or older versions ndash; No longer supported and installed on the shared hosting platform. VPS and Dedicated hosting accounts not utilizing an “admin user” will lose PHP 5.2 support starting February 16, 2015.
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 may even notice error messages or deprecated warnings on your site if the code is out of date.
Upgrading your site (if you're moving to Ubuntu from Debian servers)
|Important:||As a reminder, PHP 5.2 has been EOLed by php.net and will no longer be supported by DreamHost for Shared customers as of November 3, 2014 and for VPS and Dedicated customers starting February 16, 2015 (not including admin customers)|
If your site was recently moved to Ubuntu (which requires PHP 5.3), you may need to make some changes especially if you set up a custom PHP.ini file, manually edited your .htaccess file, or used a script to force PHP 5.2 on your site:
- Check your current PHP version in the panel as described above.
- If you're running an older version, upgrade to at least PHP 5.3.
- Log into your site via FTP.
- You can read more in the /FTP wiki.
- Edit your .htaccess file.
- Comment out any custom PHP references on your site's .htaccess files to ensure that your site loads without issue.
- For example, add a # symbol at the beginning of any line referencing "php.ini" or "dispatch".
- The scripts look like this:
AddHandler fastcgi-script fcg fcgi fpl AddHandler php-fastcgi .php Action php-fastcgi /cgi-bin/dispatch.fcgi
AddHandler php-cgi .php Action php-cgi /cgi-bin/dispatch.cgi
If you'd like to add back any custom PHP settings, you may do so by following the steps outlined in the sections that follow.
How to add a phprc file
You can create a phprc file through an FTP client, or by logging into the server via SSH. Since creating a phprc file is simpler through an FTP client, we’ll start with those steps.
Adding a phprc file through Filezilla
- Log into your web server via FTP. Visit our wiki for detailed instructions:
- Make sure you’re in your users directory.
- You can see this in Filezilla in the ‘Remote site:’ field. It will say "/home/username".
- In the users directory, right-click your mouse and select Create directory.
- Name this directory .php. Make sure you add the period at the beginning of this filename or it will not work. Visit our wiki on how to enable hidden files if you can’t see this:
- The name of this directory is the version of PHP you’re using. In this example, we’ll say our site is running PHP 5.5.
- Click into this new .php directory, and then create another directory.
- Create a folder named ‘5.5’.
- Click into this 5.5 folder, and then right-click and choose Create new file.
- Name the new file 'phprc'. DO NOT add a file extension, as the phprc file should never have an extension.
- Right-click on the phprc file, and then choose View/Edit.
- A default text editor opens for you to add your customizations. These examples are very general – adjust as needed for your site.
- When you try to save this file in Filezilla, the following popup box opens.
- Check the box which says ‘Finish editing and delete local file’, and then click the Yes button to save.
The phprc file is createded on your web server for any domains under this specific username using this specific version of PHP.
Adding a phprc file via SSH
- Log into your server via SSH. Visit our wiki for instructions on how to do this based on which operating system you’re using:
- Make sure you’re in your users directory by typing in ‘pwd’ to confirm:
[horsetail]$ pwd /home/dhwikiuser
- Run the following command:
mkdir -p ~/.php/5.5
- Change your directory into these two new folders you just created, and then run the following:
- When you run pwd, you now see the entire filepath you just created:
[horsetail]$ pwd /home/dhwikiuser/.php/5.5
- In this folder, cereate the phprc file without an extension.
Note: There are a few programs you can run to create this file, and in this example we’ll using a program called nano.
- Run the following to create the phprc file.
- A text editor pops up.
- In the editor, enter all the PHP customizations.
- When finished, press CTRL + X on your keyboard.
- You are prompted to save the file.
- Type in the letter y to confirm, and then click the Enter button to save.
The phprc file is created on your web server for any domains under this specific username using this specific version of PHP.
If you don't see the changes made to your phprc file
It’s possible that even if you’ve correctly added the phprc file, you may not notice its customizations resolving online.
Here a few suggestions to get this file updated:
- Log into your server via SSH.
- Once you log in, run the following command based on your version of PHP to kill off all running PHP processes:
For PHP 5.3:
killall -9 php53.cgi
For PHP 5.4:
killall -9 php54.cgi
For PHP 5.5:
killall -9 php55.cgi
For PHP 5.6:
killall -9 php56.cgi
Killing off your PHP processes in this way should update your phprc file.
The examples above explain how to add a phprc file with some basic contents. This section goes a little further into what you can add to this file.
|Note:||Some variables (in particular, |
By default, DreamHost does not log PHP errors. However, you can enable PHP error logging through your phprc file. Enabling PHP error logging is a simple step that allows easier diagnosis of problems with your website:
- Add these lines to your phprc file:
log_errors = 1 error_log = /home/USERNAME/php.log
- Replace USERNAME with your SHELL user.
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 directives:
upload_max_filesize = 100M post_max_size = 105M max_execution_time = 500 max_input_time = 500
|Note:||To upload large files, post_max_size should be larger than upload_max_filesize.|
Increasing the PHP Memory Limit
|Note:||If you find you're increasing the memory a large amount, it's time to consider moving off of shared hosting, as your website has greater needs than shared hosting can reliably provide.|
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
Turning off PHP errors and warnings
If you upgrade the PHP version on your site, you may suddenly see various errors messages. We always recommend that you check each message, but if you’re sure they are not causing any issues with the functionality of your site then you can remove them.
To remove the error messages, add these lines to your phprc file.
display_errors = off error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
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 phprc file 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:
Loading PHP Extensions
Depending on which version of PHP you choose to use, you may notice certain extensions are not enabled by default (for example, phar).
To load and extension, add the following line your phprc file:
extension = phar.so
Compiling PHP extensions
For steps on how to compile and load your own extensions, please visit the link below:
Adding global custom changes (VPS or Dedicated ONLY)
If you have a VPS or Dedicated server it’s also possible to set a single php.ini file for the entire server, rather than set them up individually as explained above.
The following steps will walk you through how to set this up.
|Note:||If you still have a custom phprc file setup under your user, this will override the global php.ini file for that specific user for the version of PHP for which the custom phprc file was created.|
- Log into your server using your admin user. You can create an admin user in your panel at (Panel > ‘VPS’ > ‘Admin Users’).
Tip: Visit our SSH wiki for information on how to log into your server based on the operating system you’re using:
- Once you log into your server, navigate to the directory for the version of PHP you wish to edit:
- For PHP 5.3
- For PHP 5.4
- For PHP 5.5
- For PHP 5.6
- Once you are in that directory, you’ll see the php.ini file.
- Run the following command to edit it:
sudo nano php.ini
- Make any adjustments and save.
- Kill off any PHP processes to update the file.
Once you finish, the global php.ini is now used for all sites on your server which do not have a custom phprc file set up.
|Note:||If your server is using NGINX, you must stop NGINX before killing PHP, then restart it.|
To stop/kill/restart NGINX:
sudo /etc/init.d/nginx stop pkill -9 php sudo /etc/init.d/nginx start
Loading PHP extensions on all domains (on VPS or dedicated)
On a DreamHost VPS or Dedicated server, you can find the directory at
/etc/php54/conf.d/ (just make sure to change the php# folder to the actual version you’re updating). Any files in this directory are loaded by all PHP interpreters for this version of PHP.
All custom phprc files can be created with the instructions above for your nginx machine. However, if you need to update your changes, run the following command under your admin user:
sudo /etc/init.d/nginx restart