Drush PHP memory limit

With the default PHP settings, Drush will probably get a fatal error because the PHP memory limit is too low. Thankfully, the solution is very simple.

The Problem

You are using Drush and you get the following fatal error:

  1. Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to
  2. allocate 30720 bytes) in
  3. /var/www/path/to/site/sites/all/modules/modulename/modulename.module
  4. on line 1271

The Solution

The solution is pretty straight forward. You need to increase the memory limit in the CLI version of php.ini. You may have already increased the memory limit in the Apache2 version but forgotten about the CLI version.

Assuming you are running Linux, Mac OSX or similar, open the php.ini in nano (or your preferred editor):

  1. sudo nano /etc/php5/cli/php.ini

Search for memory_limit. By default, this will be set to 32MB. Increase this to 256MB and save and close the file.

That is it!

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"

Feeling stuck with Drupal 8 module dev?

Get the free 7 lesson course that will help you get started today without feeling overwhelmed.

  • Create Drupal modules with just a few commands using the Drupal Console
  • Create custom pages
  • Create custom blocks
  • Create admin forms
  • Demystify routers and controllers
  • Bonus material

Find out more

Add new comment