Composer killed while updating
Asked Answered
F

20

188

I got a problem, I tried to install a new package to my Laravel 4 project. But when I run php composer.phar update I get this:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Killed

I have looked for the problem in the Internet and saw that the memory is the problem, I think I don't have enough RAM available, I've checked this I have about 411mb free. Does composer really need more RAM?

Finegrain answered 18/12, 2013 at 20:29 Comment(0)
P
415

The "Killed" message usually means your process consumed too much memory, so you may simply need to add more memory to your system if possible. At the time of writing this answer, I've had to increase my virtual machine's memory to at least 768MB in order to get composer update to work in some situations.

However, if you're doing this on a live server, you shouldn't be using composer update at all. What you should instead do is:

  1. Run composer update in a local environment (such as directly on your physical laptop/desktop, or a docker container/VM running on your laptop/desktop) where memory limitations shouldn't be as severe.
  2. Upload or git push the composer.lock file.
  3. Run composer install on the live server.

composer install will then read from the .lock file, fetching the exact same versions every time rather than finding the latest versions of every package. This makes your app less likely to break, and composer uses less memory.

Read more here: https://getcomposer.org/doc/01-basic-usage.md#installing-with-composer-lock

Alternatively, you can upload the entire vendor directory to the server, bypassing the need to run composer install at all, but then you should run composer dump-autoload --optimize.

Prichard answered 20/12, 2013 at 8:29 Comment(8)
When I uploaded composer.lock and run composer install worked. Thanks!Irresolute
This do not work for me, composer was installer by apt, so I remove it and install manually, then all work fine.Fuddyduddy
I'm having this issue on a local machine.Odeliaodelinda
For local development for sure go with @Balmipor's Answer, or any other server with a small amount of ram.Synovitis
Andreas, Solved by up memory limit from php.iniTalie
In case you were like me, even if the memory limit is sky high check still your machine / container max memory.Situation
I was in troubling since last 4 days and finally has fixed by the "composer dump-autoload --optimize". thanks!. you saved me.Plato
In a linux machine with journalctl, you can run journalctl | grep oom to print the logs related to processes killed due to Out of Memory (or journalctl -n 1000 | grep oom to search only in the last 1000 logs). In my case, I had a process running in a docker container that had the memory limit defined as 256MB, and the process in it was killed due to OOM, so i increased the maximum allowed memory for the container and solved the problem.Minus
R
124

If like me, you are using some micro VM lacking of memory, creating a swap file does the trick:

#Check free memory before
free -m

mkdir -p /var/_swap_
cd /var/_swap_

#Here, 2G ~ 2GB of swap memory. Feel free to add MORE
sudo fallocate -l 2G swapfile

chmod 600 swapfile
mkswap swapfile
swapon swapfile
#Automatically mount this swap partition at startup
echo "/var/_swap_/swapfile none swap sw 0 0" >> /etc/fstab

#Check free memory after
free -m

As several comments pointed out, don't forget to add sudo if you don't work as root.

btw, feel free to select another location/filename/size for the file.
/var is probably not the best place, but I don't know which place would be, and rarely care since tiny servers are mostly used for testing purposes.

Rout answered 25/1, 2016 at 17:41 Comment(11)
return swapon: swapfile: swapon failed: Operation not permitted , Why?Bissau
@Muhammad Dyas Yaskur If you have no permission problem (be sure to either work as root or use sudo), do you have anything else particular in your configuration (OS, type of drive, etc.) ?Rout
@Rout I already used as root but still not permited, my os is centos 7.0. [root@server _swap_]# dd if=/dev/zero of=swapfile bs=1M count=1000 1000+0 records in 1000+0 records out 1048576000 bytes (1.0 GB) copied, 2.79954 s, 375 MB/s [root@server _swap_]# ls -l total 1024004 -rw------- 1 root root 1048576000 Feb 6 02:12 swapfile [root@server _swap_]# mkswap swapfile Setting up swapspace version 1, size = 1023996 KiB no label, UUID=b3f1110e-5f43-4d1f-bbb1-71cad96680f9 [root@server _swap_]# swapon swapfile swapon: swapfile: swapon failed: Operation not permittedBissau
After I research it's caused by my VPS, unix.stackexchange.com/questions/2893/…Bissau
And using df -h. I got this about physical memory was full.Flunk
It's best to run thosw commands in root model. ``` sudo su```Mustee
When adding '/var/_swap_/swapfile none swap sw 0 0' to /etc/fstab you may have to do it with vim or nano. I had permission issues and using sudo did not work by appending directly to the file as in the example.Synovitis
@Shawn What distribution is it, and do you know why using sudo didn't work ? The only idea which comes to my mind would be SELinux.Rout
@Rout I use the Laravel Homestead box * Homestead v10.12.0, v11.0.2 * Settler v9.5.1 (Ubuntu 18.04) * Settler v10.0.0 (Ubuntu 20.04) I would thank that had i done "sudo su" then it would have worked without sudo.Synovitis
Swapfile did the trick for me too: stefvanlooveren.me/blog/…Dowitcher
@Hackinet Thanks for your edit. I got 2 questions about it : 1: You added a sudo. Thats good, but is it really the only one necessary in the whole process ? If not, it would be quite inconsistent. (I chose to keep sudos as "an option" because I consider one can afford to work directly as root on small disposable VMs) 2: fallocate looks way better/cleaner than dd, but is it as universal as it ? I suppose it is, but just would like to ensure the less prone-to-be-unavailable tools are suggested, so that this post still solves an issue, rather than creating a new one :)Rout
K
28

Unfortuantely composer updates require a lot of RAM & processing power. Here are a few things that I did, which combined, made the process bearable. This was on my cloud playpen env.

  1. You may be simply running out of RAM. Enable swap: https://linuxize.com/post/create-a-linux-swap-file/
  2. use a secondary terminal session running top (or htop) to watch memory/swap consumption until process is complete, you can also use this in advance to stop any memory hogging processes.
  3. For example: service mysql stop will stop mysql, but don't forget to start it after the upgrade: service mysql start
  4. composer.phar update --prefer-dist -vvv (verbose output [still hangs at some points when working] and use distro zip files). Maybe try a --dry-run too?
Kolyma answered 30/7, 2014 at 15:44 Comment(3)
I replaced top by htop, more convenient.Glyceric
Also look into creating swap fileProfiteer
after stoping mysql services, it works for me. Thanks @KolymaOrnamentation
B
22

DigitalOcean fix that does not require extra memory - activating swap, here is an example for 1gb:

in terminal run below

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1

The above solution will work until the next reboot, after that the swap would have to be reactivated. To persist it between the reboots add the swap file to fstab:

sudo nano /etc/fstab

open the above file add add below line to the file

/var/swap.1 swap swap sw 0 0

now restart the server. Composer require works fine.

Boxfish answered 17/8, 2018 at 13:1 Comment(0)
P
20

I've got this error when I ran composer install inside my PHP DOCKER container, It's a memory issue. Solved by increasing SWAP memory in DOCKER PREFERENCES from 512MB to 1.5GB

To do that:

Docker -> Preferences -> Rousources

enter image description here

Pantagruel answered 16/4, 2020 at 22:32 Comment(1)
Increased my Swap from 1GB to 2GB and it worked!Psid
M
16

Increase the memory limit for composer

php -d memory_limit=4G /usr/local/bin/composer update
Monotheism answered 10/12, 2018 at 21:55 Comment(0)
B
12

Run composer self-update and composer clearcache remove vendor and composer.lock restart your local environment and then run php -d memory_limit=-1 /usr/local/bin/composer install

Bussard answered 27/8, 2019 at 22:0 Comment(0)
S
5

If you're using docker you can use COMPOSER_PROCESS_TIMEOUT

environment:
  COMPOSER_MEMORY_LIMIT: -1
  COMPOSER_PROCESS_TIMEOUT: 2000 #seconds

Also in big projects composer needs more RAM than 2GB, you can check that with ps -aux while it is running. You will have to add it manually inside docker options, nothing else will help.

enter image description here

Spirketing answered 11/5, 2020 at 10:40 Comment(1)
The docker ram increase was the key!Counselor
S
4

Here's how I succeeded in installing maatwebsite\excel package from composer in Laravel Framework:

  1. I download composer.json file and composer.lock file from my remote server.
  2. I run composer update from local command prompt (then wait until all the install process finished).
  3. Upload composer.lock file to remote server.
  4. run composer install on remote server (then wait until all process finished).
  5. DONE
Suddenly answered 6/7, 2020 at 4:46 Comment(0)
E
3

composer 2 update have reduced the memory usage

composer self-update
composer update
composer require xxx
Enjoyment answered 1/11, 2020 at 16:14 Comment(0)
H
1

Fix for AWS ec2 Ubuntu Server Php Memory Value Upgrade For Magento 2.3.X

  • Php 7.2 / 7.3
  • nginx
  • ubuntu
  • composer 1.X
  • mariaDB
  • magento 2.3.X

Error : Updating dependencies (including require-dev) Killed for

  1. Ram Must at least 4GB
  2. Change instance type to suitable or Upgrade Ram
  3. Php Memory Value change
  4. Server Restart
  5. Try to install the same package again

PHP value update may locate under '/etc/php/7.2/fpm/php.ini' depend on your server and PHP fpm X.XX version

Using Seed command 'change as your server requires' on my case >> /etc/php/7.2/fpm/php.ini

memory limit type as "3.5G" or "3500MB" Php 7.2.X

sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.2/fpm/php.ini
  

Php 7.3.X

  sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.3/fpm/php.ini

Test if applied on 'free -h' command

    free -h

Install-Package Again#

Install extension via Composer

go to your Magento 2 installation directory

cd /var/www/html/

with 'superuser' privileges

sudo su

Start installation

composer require XXXXXX/XXXXXXX

Enable Module s

php bin/magento module:enable XXXXXX/XXXXXXX


php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
Restart
sudo reboot

Enjioy

Hispaniola answered 26/11, 2020 at 9:20 Comment(0)
V
0

I was facing this same issue on my ec2 instance, following steps worked for me :

  1. Copied composer.lock file from my local environment to ec2.
  2. then run sudo composer install and its simply installed all the dependencies for my project.
Vicegerent answered 6/4, 2021 at 6:36 Comment(0)
R
0

I solved it maintaining the below steps in my ubuntu server. Hope it will works for you.

  • Stop my apache server

    sudo service apache2 stop

  • Run composer update

    sudo composer update

  • Start my apache server

    sudo service apache2 start

Repose answered 17/5, 2021 at 22:10 Comment(0)
T
0

I was using:

  • Virtualbox
  • 4096 Gb RAM
  • 2 CPU
  • 10 GB HDD (500 MB swap)
  • Ubuntu 20.04

Running:

  • composer update in a laravel 8 project folder

I didn't set the swap for the virtual machine, so Virtualbox created a 500Mb swap space, which was NOT enough.

So composer was using 4Gb of RAM plus swap.

I gave more swap space to the VM and then it worked.

As the picture below, composer used all my RAM + 2GB of swap

System Monitor

Token answered 20/8, 2022 at 16:29 Comment(2)
How does this resolve the given problem? Usually, Composer would not use that much memoryCrazyweed
yes it does use that much memory. for example in our project, it is using 8 GB of ram and all 4gb of swap so i ended up increasing the swap moreAllix
A
0

You can run the composer without memory limitations of php

php -d memory_limit=-1 `which composer` update

Allix answered 2/3, 2023 at 11:7 Comment(0)
V
-1

php -d memory_limit=5G composer.phar update

Valdemar answered 18/2, 2019 at 8:44 Comment(2)
Please add some explanation to your code such that others can learn from itCrazyweed
please specify what does this code do and where to apply... @AliLargo
A
-1

Solved on Laravel/Homestead (Vagrant Windows)

  1. Edit Homestead.yaml and increase memory from 2048 to 4096

  2. vagrant up

  3. vagrant ssh

  4. Install Symfony with this line on the folder you choose (must be without files)

    COMPOSER_MEMORY_LIMIT=-1 composer create-project symfony/website-skeleton . -s dev
    
Arnitaarno answered 26/8, 2019 at 20:6 Comment(0)
M
-1

I get this problem caused for a package that don't update correctly with wildcards, I use directly the last version and it works finally.

"l3/cas-bundle": "~1.0" -------> "l3/cas-bundle": "1.1.13"

Mcneil answered 9/9, 2019 at 10:13 Comment(0)
T
-4

You can try setting preferred-install to "dist" in Composer config.

Tenorio answered 26/12, 2017 at 8:36 Comment(2)
This question is about installing some Laravel project. How is your answer related to it?Crazyweed
This question is about installing a package. Specifically, it is about problems with installing a package that are related to RAM. Why I included information about WP in the answer 2 years ago? I don't know. I've now updated the answer, which IMO is very relevant now.Tenorio
B
-5

I was getting this error in a local Docker environment. I solved it by simply restarting Docker.

Borborygmus answered 19/7, 2019 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.