I know this question can be found a lot of time on this forum and the internet. But I can’t seem to find the answer to my specific question.
I’m running a Drupal website, and since the update of MAMP from 5.5 to 5.6 I get the following error:
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes)
when running a composer require
in the terminal.
I updated the php.ini tot 1024MB instead of 128MB of the current php version I’m running via MAMP. When I add a php file to my root with <?php phpinfo(); ?>
I see that the memory is like I want so 1024MB. When I look at the location of the php ini file I see it is in the MAMP folder.
But I still get the error. When I run this php -r "echo ini_get('memory_limit').PHP_EOL;"
in my terminal I see the 128MB again. When I try to find the php ini that is running using
I get:
php -i|grep 'php.ini'
Configuration File (php.ini) Path => /etc
So it looks like the php.ini file is somewhere else. But I don’t know where and can’t change it. How can I solve this?
I also tried changing the composer memory using php -d memory_limit=-1 /usr/bin/composer
but this didn’t solve the problem either.
My question is, how can I solve this problem? How can I find the php.ini file that is used. Or how can I change the memory limit?
Update:
Running php -i | grep 'Configuration File'
in the terminal ouputs:
Loaded Configuration File => (none)
And maybe good to know that I have the option Make this version available for command line enabled on the MAMP php section.
3
Answers
I ended up adding a
php.ini
file to the/etc
folder on my computer. This way the php memory_limit raise did work. And checking it in the terminal did show me the right value. But as Alister already said, this didn't fix the problem. The problem was not in thephp.ini memory_limit
.I found out that using
COMPOSER_MEMORY_LIMIT=-1
in the terminal at the beginning of my session put the memory limit to unlimited during that terminal session. This fixed the problem.After that I added,
alias composer="COMPOSER_MEMORY_LIMIT=-1 composer"
to my bash file and know everything is working like I would expect.Changing the amount of memory in php.ini won’t help – that is the limit for what is being used by the webserver’s version of PHP – and having too much available for the webserver can cause problems (at least when running in production).
Composer, when it is being run from the command line, will, by default set the limit to 1,610,612,736 bytes – 1.5 GB.
As you are apparently still on PHP 5.6, that’s also a very considerable problem.PHP 7+ is a great deal more efficient with memory, as would be an up to date version of composer.Finally, to actually solve the problem: Restrict your requirement to be more specific since that keeps memory usage lower.
I tried many of the suggestions on this and a few other stack overflow questions but couldn’t get it to work until I tried:
Just trying COMPOSER_MEMORY_LIMIT=-1 by itself before running the command didn’t seem to work. Not sure why, but I had to run them on the same command line in a similar way as documented in the composer troubleshooting: https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors