How to fix the «Fatal error: Allowed memory size exhausted in Composer/Cache.php»?

You can get this error while executing the composer require command (e.g. on the Step 8 of the Mage2.PRO installation instruction):

The error is caused by a wrong PHP memory_limit option value.
You can check it from the command line:

php -i | grep memory_limit

You will see something like:

As you can see, the memory_limit value is 512 megabytes, but Magento 2 requires 2GB:

Upgrading the Magento applications and extensions you obtain from Magento Marketplaces and other sources can require up to 2GB of RAM. If you are using a system with less than 2GB of RAM, we recommend you create a swap file; otherwise, your upgrade might fail.

You can also try to disable the memory limit for a particular Composer command.


php -d memory_limit=-1 composer.phar require --prefer-source mage2pro/stripe:*

Hi, Actually I’ve faced with composer memory limit error such error you dicussed here, I just wanted
to know should running related commands " ```
php -d memory_limit=-1 composer.phar <…> " be on my magento root directory or should be on my root server user? as I got some syntax error after runnig command on my server root
like "bash: syntax error near unexpected token `newline’ " or command not found. It would be greatly appreciated for any help.