PHP Settings on DreamHost

Recently, I needed to make some modifications to the PHP.ini settings on a shared DreamHost server. Specifically, I needed to increase the file upload size limit (the default was only 7 MB) and increase the PHP memory limit a bit. This turned out to be much easier than I expected.

Changing the PHP.ini settings on a shared server works by creating a phprc file for each version of PHP you want to alter. Any settings in the phprc file will override the ones in the PHP.ini file. Any settings not specified in the phprc file will default to the server PHP.ini file.

The following steps have been pulled out of the PHP.ini page in the DreamHost wiki. Read this page if you’re curious about any limitations that this method might have.

  1. Determine which PHP version your website uses. The easiest way to do this is to login to your DreamHost panel, navigate to the “Manage Domains” section, and click edit next to the domain. On the edit page, you will be able to see the PHP version that has been selected for that domain.
  2. Open a terminal and SSH into your DreamHost server.
  3. Create a new directory in your user home directory that will store a phprc file with custom PHP.ini settings. For PHP 5.3 run this command:
    mkdir -p ~/.php/5.3
    

    or for PHP 5.4, run this command:

    mkdir -p ~/.php/5.4
    
  4. Inside your newly created directory, add a phprc file by running this command:
    touch phprc
    
  5. Edit the phprc file to add your custom settings. At this point, I find it easier to just SFTP into the server and edit the file. Just make sure you have your “view hidden files and folders” option turned on.
  6. Add your custom settings. For an example, here are the settings I added to increase file upload and memory limits:
    upload_max_filesize = 64M
    post_max_size = 64M
    max_execution_time = 500
    max_input_time = 500
    
    memory_limit = 128M
    
  7. Force PHP to reload. To do this, run the following command for PHP 5.3:
    killall php53.cgi
    

    or run this command for PHP 5.4:

    killall php54.cgi
    

That’s it! Your custom PHP.ini settings should now be in effect.