How to increase the PHP 7.2 memory_limit on Mac OS
I just ran a simple composer require [...]
command in a Laravel project on my local machine.
And so it begins!
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted [...]
Really? Locally, on my computer? Anyway, Composer has a helpful section covering this topic on the Troubleshooting page.
So I ran the command below and it told me the memory limit only was 128 mb.
$ php -r “echo ini_get(‘memory_limit’).PHP_EOL;”
Okay, so I just have to change a value in my php.ini
file. But where is it?
This command will tell you:
$ php --initConfiguration File (php.ini) Path: /usr/local/etc/php/7.2
Loaded Configuration File: /usr/local/etc/php/7.2/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d/usr/local/etc/php/7.2/conf.d/php-memory-limits.ini
So I opened up the/usr/local/etc/php/7.2/php.ini
file and changed the memory_limit
setting from 128
to -1
Nothing happened!
But the problem remained. Now what?
It turned out that if I ran php --init
again and took a more careful look, the php-memory-limits.ini
file that is listed sounds like something I should do something with.
; Max memory per instance
memory_limit = 128M;The maximum size of an uploaded file.
upload_max_filesize = 128M;Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize
post_max_size = 128M
There we have it! Once again, I changed memory_limit
from 128M
to -1
And the final touch:
$ brew services restart php
There we have it!