Is 1GB RAM enough for installing composer and laravel?

July 16, 2019 241 views
LAMP Stack PHP Frameworks

Debian 9 (1 GB RAM, 25 GB storage)
Apache
MariaDB
PHP 7.2

Composer and Laravel installed successfully

Then, attempted to add a package with composer ...
ran following line in Putty
composer require mobiledetect/mobiledetectlib

returned the following...

Using version ^2.8 for mobiledetect/mobiledetectlib
./composer.json has been updated
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 878714880) (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

Fatal error: Out of memory (allocated 878714880) (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

Checked for the mobiledetect folder in /var/www/domainname/html/projectname/vendor but no folder there

Currently have 1 GB RAM in DigitalOcean, do I need to up it to 2 GB RAM for composer to run updates properly?

I ran the command ...
php -r "echo iniget('memorylimit').PHP_EOL;"
and -1 was returned which means unlimited

I checked the php.ini file and found...
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = -1

I used the 'top' command to view that only 1 % of CPU is in use

and free -m returns
total used free shared buff/cache available
Mem: 996 134 800 21 60 750

I read that composer increases internal memory to 1.5 GB here https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors

Any suggestions would be appreciated.

1 Answer
bornbeeagency July 16, 2019
Accepted Answer

The OS you're using plays an integral role in memory management, one of the easy hacks to eliminate these memory errors is to add Swap memory file and SSD storage also helps in faster swaps. Refer to the tutorial below:
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-7

by Josh Barnett
One of the easiest ways to make your server more responsive, and guard against out-of-memory errors in your application, is to add some swap space. This gives you the ability to increase the amount of information that your server can keep in its working memory. In this guide, we will cover how to create and enable a swap file on a CentOS 7 server.
  • BornB, thanks for your answer. The link you provided gave me the info I needed. Looks to me I have to upgrade since the use of Swap memory is recommended only for spinning hard disks. I will upgrade my DigitalOcean account to 2GB RAM.
    John

    When I logged in today, I could view the mobiledetect folder in the /.composer directory but the folder was absent for the project in the vendor directory, I ran 'composer update' in my project folder but failed due to memory again. Powered off the droplet and resized to 2GB RAM. Now 'composer update' ran successfully and I can view that the 'mobiledetect' folder has been added to the vendor directory for my project.

Have another answer? Share your knowledge.