Fix Composer Memory Error - PHP Fatal error: Allowed memory size of xx bytes exhausted



I got this error while installing a Laravel package today and got it fixed so easily.

The exact error was this:

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors. 


To fix this, you can either increase the memory limit for php, or ignore the memory limit for this command at the time you run this. I opted for the second method as I wanted to do this just one time.

Just run the same command as below:

php -d memory_limit=-1 <composer-bin-path> require <package-name>
Ex:
php -d memory_limit=-1 /usr/local/bin/composer require kreait/laravel-firebase

You can find the path for composer by using the following command. which composer
vagrant@homestead:~/$ which composer
/usr/local/bin/composer


Hope this will help someone.