Composer Memory Problem on Shared Web Hosting

Posted on: Mon, 08/03/2020 - 04:27 By: admin

If you are using shared web hosting for your composer managed Drupal website, you have probably ran into the problem of your server running out of memory for simple commands such as "composer install". Shared web hosting usually have memory limits which are shared across many websites.

This problem becomes quickly apparent if you are trying to install a new Drupal website into your shared hosting account. Because this is probably the first time that you have to run "composer install" for this website. Composer will then have to go and fetch all the files and download them into your vendor directory. The high memory consumption in composer is mostly due to dependency resolution. This process is memory intensive. The end result is your process is abruptly killed without finishing.

Solution

A quick and easy solution is to install the site locally whereby you can successfully run "composer install". You would then have the vendor directory locally. Then use a service like FTP to manually upload the vendor folder into the correct directory on your hosting server. Then on your hosting server, try running "composer install" again. 

At this point, composer would not need to fetch all the files again. Composer may or may not have to update some files in the vendor directory. This is OK. But the process should now be able to complete within your memory limitations.

It should be noted that the vendor directory should not be committed to your git directory for a few important reasons. 

There are arguments for and against committing the vendor directory. It is not technically wrong but there some risks associated with it. The recommendation about not committing /vendor to the git repo is mostly related to avoiding headaches with git submodules (duplicated history, etc). The composer docs page shows some ways that you can prevent hitting those.

I've used the following to overcome this issue and it works fine:

 

COMPOSER_MEMORY_LIMIT=-1 composer require ...

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
English