Composer Cannot Allocate Memory

I using composer to setup extension, but it error Cannot Allocate Memory. I was set memory_limit=-1, but it not run.

Hi @duypham2991 and welcome.

I don’t recommend the use of memory_limit=-1

1. Check: Ensure you have enough available Memory

First, make sure your server has a minimum of 2GB of available Memory so that composer can be run without hanging ("out of memory").

2. Option A: Upgrade

Upgrade server specs. As of July 2020, I’m now recommending 4G memory servers. If you upgrade your server, don’t forget to update your php.ini and .htaccess variables to take into account the new memory_limit.

3. Option B: Allocate a temporary swap file

If you do have a minimum of 2GB of available Memory, then try to allocate a temporary swap file.

4. Option C: Set memory_limit during command

I also like this one. Obviously, only set the memory_limit (4G) to whatever you have available in your environment:

php -d memory_limit=4G /usr/local/bin/composer command
php -d memory_limit=4G /usr/local/bin/composer update
php -d memory_limit=4G /usr/local/bin/composer require example/example