Allowed memory size of 536870912 bytes exhausted in Laravel

You can try editing /etc/php5/fpm/php.ini:

; Old Limit
; memory_limit = 512M

; New Limit
memory_limit = 2048M

You may need to restart nginx:

sudo systemctl restart nginx

You may also have an infinite loop somewhere. Can you post the code you're calling?


I realize there is an accepted answer, and apparently it was either the size of memory chosen or the infinite loop suggestion that solved the issue for the OP.

For me, I added an array to the config file earlier and made some other changes prior to running artisan and getting the out of memory error and no amount of increasing memory helped. What it turned out to be was a missing comma after the array I added to the config file.

I am adding this answer in hopes that it helps someone else figure out what might be causing out of memory error. I am using laravel 5.4 under MAMP.


Edit the following two files (you may only have one of them):

sudo nano /etc/php/7.3/fpm/php.ini

sudo nano /etc/php/7.3/cli/php.ini

Change the memory limit, for example from 512M to 1024M:

memory_limit = 1024M

Restart nginx:

sudo systemctl restart nginx

Check the memory_limit

php -i | grep "memory_limit"

Run your software to check if the new memory_limit is sufficient.

If not, increase it again (and repeat the steps above). To 2048M, for instance:

memory_limit = 2048M

It is happened to me with laravel 5.1 on php-7 when I was running bunch of unitests.

The solution was - to change memory_limit in php.ini but it should be correct one. So you need one responsible for server, located there:

/etc/php/7.0/cli/php.ini

so you need a line with

 memory_limit

After that you need to restart php service

sudo service php7.0-fpm restart

to check if it was changed successfully I used command line to run this:

 php -i

the report contained following line

memory_limit => 2048M => 2048M

Now test cases are fine.

Tags:

Laravel