Amazon EC2: Fix for Error When Using Composer.phar
When using The Composer dependency manager for PHP, people will occasionally experience errors when using Amazon’s EC2 service. A simple fix exists for this issue.
Recently, when trying to install Symfony2 on an EC2 instance, I found the following error:
“Uncaught exception ‘ErrorException’ with message ‘proc_open(): fork failed – Cannot allocate memory’ in phar…”
In debugging this issue, I found that a lot of people were experiencing this same issue. Typically this occurs when using Composer.phar on a t1.micro instance. The small memory footprint of this instance does not have enough swap memory for Composer.phar to execute correctly.
Increase Instance Size
To correct this issue, just temporarily change your instance to a larger instance. You can do this by stopping the instance and then selecting Change Instance Type from the Actions menu. You may have to adjust your IP address and security depending on configuration.
After you have increased your instance capabilities, use composer.phar to install your PHP data. After you have finished, then feel free to stop the instance and downgrade again if you wish to save money. Once again you may have to change your IP address and security settings.
Increase PHP Limits
Alternatively, you can increase your PHP memory_limit to at least 256M. Often this will give PHP enough free memory to run composer without the errors.
View more articles by David Kirk
Follow the reactions below and share your own thoughts.