Solution: Composer cannot allocate memory or composer process killed

This error is caused due to the insufficient memory available to run composer. There are several solutions to solve this problem. Most of them are listed on stackoverflow.com. However, I’m gonna show you an alternative way to install/update a library on your production server.

Follow these steps to get rid of the problem:

  1. Set up your project locally using your preferred server environment. For Php, you may use XAMPP/MAMP.
  2. Install Composer on your local machine.
  3. Install a library/plugin on your local machine. It won’t give you the memory error.
  4. Open composer.lock file in your preferred text editor and look for the library/plugin name.
  5. Copy the whole block corresponding to that library/plugin.
  6. Don’t worry about its dependencies. Even if you don’t copy them now, while installing these libraries on your production server, the composer will give you a warning that those dependencies are required and you can copy those blocks from the local composer.lock file and paste it on to your production composer.lock file. Run the composer install again.
  7. Run the command composer install inside your project directory. (where the composer.json and composer.lock files are located)
  8. Success! Composer will install the libraries with their required dependencies.

Why did it work?

Composer install command is less memory intensive as compared to composer update.

Running low on budget? Get the best Shared hosting at an Affordable Rate!