PHP Memory Limit for Drush

I have a client with a very low-end GoDaddy account.  While this is bad, especially for Drupal development, it is still usable.  One area that I've struggled with, however, is getting Drush to work for larger tasks such as reverting Features or clearing cache.

The problem I was running into was that GoDaddy provides the shared hosts with a maximum memory limit of 64M by default.  This doesn't go very far in the Drupal world.  There are plenty of articles on how to change your PHP memory limit for the webserver, but the gist of it is this:

  1. Go to your root (~/public_html) directory (either in the cPanel file manager, SSH, or other method.)
  2. If you already have a .user.ini1 file, you will edit that.  If you don't have that file, you'll create it.
    (1 Assuming newer versions of cPanel. Older versions should use php5.ini instead.)
    • nano .user.ini

  3. This is essentially a user-defined php.ini file, and has the same values/format.  Look for or add the memory_limit value, setting the value much higher than 64M (at least 128M, but you might want to go even higher.  You might need to do trial and error to find the right value.)

    • It should be noted that the actual value is limited by your server.  If your server only provides 256M of RAM, that is the most you'll be able to provide, regardless of the setting.

  4. Save the file

Ok, so now if we run phpinfo(), we will see that the server has our new value, however, when we try to do a major task with Drush, it is still maxing out the 64M of RAM.  The reason for this is that the .user.ini file is only overriding the web server, and drush is using PHP on the command line.  These two instances barely know each other.  What we need to do is define the amount of RAM Drush can use.  To do this, we need to create a drush.ini file where Drush can see it.  We could put this in the same directory as Drush, which will probably be something like ~/.composer/vendor/drush/drush.  The problem with that is whenever drush is updated, our custom settings are lost.  We should also be able to use the location of ~/.drush, so we'll do that.

  1. Using SSH, the cPanel file manager, or some other way of editing files online, go to your home directory (~/ or /home/[username].)
  2. If you do not already have a .drush directory, create one (mkdir .drush) and change into that directory.
  3. Create a drush.ini file (nano drush.ini)
  4. At the minimum, add the following line to the file:
    memory_limit = 128M
  5. Save and exit

Now, when you try to do something with Drush, it should work as expected.  Or rather, if it still maxes out the memory, it will use your custom limit, and you can simply try increasing that.