2

I currently set up a Drupal 8 website using Composer like described here. Drupal is already running. Now I want to add Bootstrap theme by calling

composer require drupal/bootstrap

But I get

Using version ^7.3 for drupal/bootstrap ./composer.json has been updated DrupalProject\composer\ScriptHandler::checkComposerVersion Loading composer repositories with package information Updating dependencies (including require-dev)

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory PHP Fatal error: Out of memory (allocated 515907584) (tried to allocate 20480 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Pool.php on line 221

Fatal error: Out of memory (allocated 515907584) (tried to allocate 20480 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Pool.php on line 221

Im using Composer version 1.2.1 2016-09-12 11:27:19

closed as off-topic by Clive Feb 22 '18 at 17:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – Clive
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This is off-topic because composer usage is a general PHP topic. The issue has to do with the memory usage of composer update, which per the composer maintainer's words should only be used on non-production systems. This is really annoying and limiting for me personally because I like to run a build process on jenkins and this makes the jenkins build agent require some ridiculous amount of memory (> 1gb) to do composer update. This could be on-topic if the question asked about how to store composer.install for a Drupal site without using composer from scratch. – mradcliffe Sep 19 '16 at 14:21
  • See Saldaek's last comment in github.com/composer/composer/issues/5082. – mradcliffe Sep 19 '16 at 14:24
  • 2
    @mradcliffe I think this can count as on topic, since this is directly related to using composer on a Drupal site, to install (download) a new module. – googletorp Sep 19 '16 at 21:09
  • I tried to remove composer.lock and then composer install, but even then it doesn't install. So, I think, this is not alone a problem with the update command, but with install as well – JSchirrmacher Sep 20 '16 at 14:24
  • In some cases I have had the memory limit issue when using PHP 5.6 and then after switching to PHP 7.1 everything ran correctly with the same memory limit. – rooby Apr 4 '18 at 1:10
3

This is related to your php.ini file's memory_limit entry which defaults to 128M. You need access to your server's php configuration file. If you do here is the step by step for making that change on an Ubuntu server with PHP 7 and PHP CLI extension.

  1. Open the PHP CLI configuration file located at /etc/php/7.0/cli; e.g. I use vim as follows sudo vim /etc/php/7.0/cli/php.ini
  2. Search for the line containing memory_limit by pressing the / (forward slash) key, type the phrase memory_limit and press enter.
  3. Once on that line go to vim's insert mode by pressing 'ESC' followed by 'i'.
  4. Change the value for the memory_limit to something higher, e.g. memory_limit = 1024M since you already have 512M for the limit.
  5. Save and exit the configuration file by pressing 'ESC' type in 'wq' and then press 'enter'.

If you don't see any changes it could be that you have an error in you php.ini configuration file. You are always welcome to comment on the answers to get more help.

  • Why would this command require 1024M memory limit? That's really really high. – Kevin Sep 19 '16 at 18:40
  • 1
    @Kevin Composer with Drupal 8 is know for an excessive requirement of memory; if you do a quick search you will see a number of issues related to composer being out of memory when working with Drupal. I read somewhere that this is because of how Composer keeps track of dependencies and we all know Drupal has a lot of them. – tsega Sep 20 '16 at 6:50
  • I have tried it without a memory limit now (php -d memory_limit=-1 `which composer` require "drupal/bootstrap") but the result stays the same, so while it might be a problem with Drupal's mass of dependencies, it seems to be regrettably a fact that I seem to cannot use it with composer. – JSchirrmacher Sep 20 '16 at 14:21
  • Note that composer now (not sure if it used to) sets its own memory limit of 1.5GB. – rooby Apr 4 '18 at 1:09
0

The best way to fix this will be to add a swap space to the instance. Please note, this error can appear even if you set memory_limit= -1, as eventually, the system will run out of memory if the maximum memory is limited.

Please note, the commands required to execute varies with the OS variant. One example is below.

Run the following commands:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=2048

sudo /sbin/mkswap /var/swap.1

sudo chmod 600 /var/swap.1

sudo /sbin/swapon /var/swap.1

To survive a restart, append the following entry to /etc/fstab

/var/swap.1   swap    swap    defaults        0   0
  • I don't see any mention of AWS anywhere in this topic...I doubt this answer will help. – Scott Joudry Feb 22 '18 at 17:25
  • AWS was just an example. Updated the post anyway to make it clear. – Sensimple Feb 22 '18 at 17:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.