2

When attempting to run Drush on an Ubuntu 18.04 web server I'm seeing the following error :

PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 12288 bytes) in /root/.composer/vendor/drush/drush/src/internal-forks/Config/Yaml/Parser.php on line 379

I have checked with php.ini file is being loaded via the command php --ini which gives me the output;

Configuration File (php.ini) Path: /etc/php/7.2/cli
Loaded Configuration File:         /etc/php/7.2/cli/php.ini
Scan for additional .ini files in: /etc/php/7.2/cli/conf.d
Additional .ini files parsed:      /etc/php/7.2/cli/conf.d/10-mysqlnd.ini,
/etc/php/7.2/cli/conf.d/10-opcache.ini,
/etc/php/7.2/cli/conf.d/10-pdo.ini,
/etc/php/7.2/cli/conf.d/15-xml.ini,
/etc/php/7.2/cli/conf.d/20-apcu.ini,
/etc/php/7.2/cli/conf.d/20-apcu_bc.ini,
/etc/php/7.2/cli/conf.d/20-calendar.ini,
/etc/php/7.2/cli/conf.d/20-ctype.ini,
/etc/php/7.2/cli/conf.d/20-curl.ini,
/etc/php/7.2/cli/conf.d/20-dom.ini,
/etc/php/7.2/cli/conf.d/20-exif.ini,
/etc/php/7.2/cli/conf.d/20-fileinfo.ini,
/etc/php/7.2/cli/conf.d/20-ftp.ini,
/etc/php/7.2/cli/conf.d/20-gd.ini,
/etc/php/7.2/cli/conf.d/20-gettext.ini,
/etc/php/7.2/cli/conf.d/20-iconv.ini,
/etc/php/7.2/cli/conf.d/20-intl.ini,
/etc/php/7.2/cli/conf.d/20-json.ini,
/etc/php/7.2/cli/conf.d/20-ldap.ini,
/etc/php/7.2/cli/conf.d/20-mbstring.ini,
/etc/php/7.2/cli/conf.d/20-mysqli.ini,
/etc/php/7.2/cli/conf.d/20-pdo_mysql.ini,
/etc/php/7.2/cli/conf.d/20-phar.ini,
/etc/php/7.2/cli/conf.d/20-posix.ini,
/etc/php/7.2/cli/conf.d/20-readline.ini,
/etc/php/7.2/cli/conf.d/20-shmop.ini,
/etc/php/7.2/cli/conf.d/20-simplexml.ini,
/etc/php/7.2/cli/conf.d/20-sockets.ini,
/etc/php/7.2/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.2/cli/conf.d/20-sysvsem.ini,
/etc/php/7.2/cli/conf.d/20-sysvshm.ini,
/etc/php/7.2/cli/conf.d/20-tokenizer.ini,
/etc/php/7.2/cli/conf.d/20-wddx.ini,
/etc/php/7.2/cli/conf.d/20-xmlreader.ini,
/etc/php/7.2/cli/conf.d/20-xmlwriter.ini,
/etc/php/7.2/cli/conf.d/20-xsl.ini,
/etc/php/7.2/cli/conf.d/20-zip.ini

I have edited /etc/php/7.2/cli/php.ini and set memory_limit = 1024MB but the problem still exists.

It looks like the memory limit is still being set at 2MB on the command line. When I check a website set to output phpinfo() I can see that the memory_limit is equal to 1024MB.

Can anyone shed any light on a solution to my problem please?

EricLavault
  • 12,130
  • 3
  • 23
  • 45
SheppardDigital
  • 3,165
  • 8
  • 44
  • 74
  • I was wondering how these 2MB memory were eventually set ? I may have missed something, let me know. Thanks to share your feedback. – EricLavault May 25 '19 at 09:01

1 Answers1

0

You may have several versions of PHP running on your machine, a quick check : which -a php.

To see where is located drush php executable and .ini file, run drush status. Verify it relies on the correct executable first (it seems like either it relies on a wrong PHP version and/or configuration, either the .ini file you edited is not the good one).

It's possible you have drush specific config in $HOME/.drush/ or /etc/drush, check for the following lines :

 PHP executable         :  /path/to/php
 PHP configuration      :  /path/to/php.ini

If you need to change the PHP executable path, use DRUSH_PHP environment variable :

To run Drush with a specific version of php, rather than the php defined by your shell, you can add an environment variable to your the shell configuration file called .profile, .bash_profile, .bash_aliases, or .bashrc that is located in your home folder:

export DRUSH_PHP='/path/to/php'

The following environment variables as well control the settings that Drush will use :

export PHP_INI='/path/to/php.ini'
export DRUSH_INI='/path/to/drush.ini'
export PHP_OPTIONS='-d memory_limit="2"' # you might have this overriding your base config !

See Running a Specific php for Drush - it's drush 7.x documentation but works the same with drush 8.x (non tested with drush 9.x though).

EricLavault
  • 12,130
  • 3
  • 23
  • 45