DEV Community 👩‍💻👨‍💻


Posted on • Updated on

How to fix php memory limit errors

If you are having composer memory limit issues

COMPOSER_MEMORY_LIMIT=-1 composer install
This will temporary remove the php memory limit. -1 (infinite memory usage) is not recommended if the server is running a site/sites that is/are live as it could overload the server. In this scenario use a different memory size e.g.COMPOSER_MEMORY_LIMIT=512M. If the server is in maintenance mode then -1 should be fine to use, just be cautious. To find your current memory limit setting run: php -i | grep "memory_limit"

Memory limit issues in scripts

Put the following
ini_set('memory_limit', '64M');

Useful commands on Mac

To find your php.ini file run:
php -i | grep "Loaded Configuration File"

To find all php.ini files on your machine:
sudo find / -name php.ini
kill the process after the main process has finished using Ctrl + C.

To get the memory limit:
php -i | grep "memory_limit"

Useful commands on Linux

To view locations of all of your php ini files (on linux only - To install do: sudo apt install mlocate):
locate php.ini

php -i gives a print out of the ini php which your php is using.
To find he location of this ini file run:
php -i | grep "Loaded Configuration File"

Sometimes a there are two php.ini files -> like in Laravel Forge where there is one for the CLI and one for the FPM.
To view how much space is allocated in your CLI php ini file:
php -i | grep "memory_limit"

To view how much space is used in your FPM ini file (change to php version):
grep "memory_limit" /etc/php/7.3/fpm/php.ini

to view peak usage in a script:

Normal directory:
cd /etc/php/7.4

Top comments (0)

You guessed it

The most popular item in our shop is the stickers. Grab a pack today (with free shipping)!