Increase the PHP Memory Limit on a Dreamhost Virtual Private Server (VPS)

by Chadwick Wood •  April 26th, 2011

If you've ever seen a PHP error like "Fatal error: Allowed memory size of xxx bytes exhausted..." on one of your websites, then you might need to increase the memory limit for PHP on your web server. Depending on your web host, this may or may not be possible. If you have a Dreamhost VPS, then luckily it is! Here's how you do it.

Create an Admin User for Your VPS

To edit the PHP settings on your VPS, you'll need an admin user so that you can get root access via SSH. To do this, go to your Dreamhost Panel, and select "Manage Admin Users" under the VPS menu on the left. Fill out the short little form, and you're done. It takes a few minutes for this process to complete, and you'll have to wait until it is complete to do the next steps. So, give it 5 or 10 minutes before moving on.

Manage Your Own PHP

The next step is also in your Dreamhost Panel: turn off Dreamhost management of PHP on your VPS. By default, Dreamhost auto-generates the configuration file that PHP uses. Since we want to manually edit that configuration, we need to turn Dreamhost management off. Go to "Configure Server" under VPS again, and find the section of the page for "PHP Configuration". Un-check the "DreamHost Managed" box, and save. Again, you'll have to wait a few minutes to complete.

Find out Which Configuration File to Change

My VPS had multiple versions of PHP installed on it by default, and yours probably does too. So, you need to figure out which configuration file (php.ini) needs to be changed. The easiest way to do this is to have a page on your website somewhere that calls phpinfo() to show you how PHP is set up for your website. I'm going to assume you can figure that part out. Once that's set up, visit the page that calls phpinfo() and look for the line (near the top) that reads "Loaded Configuration File". That's the path of the configuration file you need to edit.

Edit Your Configuration File

Now that you know where to look, SSH into your server as the new admin user you set up, and edit that file. I use nano for command-line editing. So, if your phpinfo() page says your config file is at /etc/php5/cgi/php.ini, then just type sudo nano /etc/php5/cgi/php.ini at the command line to get in there. Note that you need to include "sudo" at the beginning (and then enter your admin password) to get permission to edit this file.

Once you're in, find the line that starts with "memory_limit", and change the number on that line to what you want your new PHP memory limit to be. It'll most likely end in "M" (for megabytes). Leave that "M" in there. Save your file, and you should be done.

Check Your Changes

After you've saved your config file, go back to your page that calls phpinfo(), and check to see that the line that reads "memory_limit" now shows the new value you entered. If it does, you should be all set! (And if not, check to make sure you didn't mess any steps up).

I hope this helps! If you're like me, you might know most of this stuff already, but it's nice to have it all laid out step-by-step. Leave any feedback in the Comments section.