PHP.ini

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 performed by DreamHost may break your modifications. You, as the user, are responsible for troubleshooting and resolving issues with your customizations.

Overview

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 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 on the (Panel > ‘Domains’ > ‘Manage Domains’) page.

You’ll see the version assigned to any domain to the right under the "Web Hosting" column:

Important:

Please be aware that DreamHost recommends you use PHP version 5.5. You can find more info about PHP here:

PHP 5.3 - 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 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.

Note:

You should be aware of the following:

PHP.net is no longer releasing security updates for version 5.2,

PHP 5.3 has been End-Of-Lifed (EOL’ed) which means the product is no longer getting security updates from the developers and php.net,

PHP 5.4 will be EOL'ed this year (September 2015),

PHP 5.5 is well tested, stable, and has been in production on sites around the world since June 2013.

Upgrading your site (if you're moving to Ubuntu from Debian servers)

Important:

As a reminder, PHP 5.2 has been EOL'ed by php.net and is no longer 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:

Adding a phprc file via SSH

Make sure you’re in your users directory by typing in ‘pwd’ to confirm:

[horsetail]$ pwd
/home/dhwikiuser

Note:

In this directory, you can run a single command to create the /.php folder as well as the /5.5 folder that goes inside of it. Remember to first check which version of PHP your site is using. In the following example, we’ll assume the site is using PHP 5.5.

Run the following command:

mkdir -p ~/.php/5.5

Change your directory into these two new folders you just created, by running the following:

cd .php/5.5

When you run pwd, you now see the entire filepath you just created:

[horsetail]$ pwd
/home/dhwikiuser/.php/5.5

In this folder, create 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 use a program called nano.

Run the following to create the phprc file.

nano phprc

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.

Customization Options

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, memory_limit, post_max_size and upload_max_filesize) 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

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:

To enable:

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 64MB, which may be far too small for your needs.

Once you log into your server, navigate to the directory for the version of PHP you wish to edit:

For PHP 5.3

/etc/php53

For PHP 5.4

/etc/php54

For PHP 5.5

/etc/php55

For PHP 5.6

/etc/php56

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

Note:

If your server is running 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.

Nginx

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

Note:

If you receive a 504 timeout on your website, you must stop nginx, kill PHP, and then finally restart nginx. Run the following commands under your admin user to update your settings:

sudo /etc/init.d/nginx stop
pkill -9 php
sudo /etc/init.d/nginx start

Troubleshooting

This section will help to resolve common errors you may encounter on your PHP website.

Turning off PHP errors and warnings

If you upgrade the PHP version on your site, you may suddenly see various error messages. DreamHost always recommends 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.

Cannot modify header information

This is essentially an issue with how the site is coded. Most often, this simply means something was sent to the browser before the header() was called. Technically speaking, once the header block has already been sent, you cannot add

additional header lines. Most often this is caused by your code sending output to the browser before the header() function. Make sure your header() function is set in your code before any output.

If you do not want to make any adjustments to your code, you can add the following in your phprc file to resolve this.