Composer killed while updating

183,487

Solution 1

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.

Solution 2

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.

Solution 3

Unfortuantely composer requires 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://www.digitalocean.com/community/search?q=add+swap (note: I think best practice is to add a seperate partition. Digitalocean's guide is appropriate for their environment)
  2. service mysql stop (kill your DB/mem-hog services to free some RAM - don't forget to start it again!)
  3. use a secondary terminal session running top to watch memory/swap consumption until process is complete.
  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?
  5. Composer is apparently know to run slower in older versions of PHP (e.g. 5.3x). It was still slow in 5.5.9 for me...

Solution 4

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.

Solution 5

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

Share:
183,487

Related videos on Youtube

cherrycoding
Author by

cherrycoding

Updated on July 21, 2022

Comments

  • cherrycoding
    cherrycoding almost 2 years

    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?

  • Ehsan
    Ehsan almost 7 years
    When I uploaded composer.lock and run composer install worked. Thanks!
  • rafaelphp
    rafaelphp over 6 years
    This do not work for me, composer was installer by apt, so I remove it and install manually, then all work fine.
  • Muhammad Dyas Yaskur
    Muhammad Dyas Yaskur about 5 years
    return swapon: swapfile: swapon failed: Operation not permitted , Why?
  • Balmipour
    Balmipour about 5 years
    @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.) ?
  • Muhammad Dyas Yaskur
    Muhammad Dyas Yaskur about 5 years
    @Balmipour 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 permitted
  • Muhammad Dyas Yaskur
    Muhammad Dyas Yaskur about 5 years
    After I research it's caused by my VPS, unix.stackexchange.com/questions/2893/…
  • afilina
    afilina about 5 years
    I'm having this issue on a local machine.
  • Nico Haase
    Nico Haase over 4 years
    Please add some explanation to your code such that others can learn from it
  • Nico Haase
    Nico Haase over 4 years
    This question is about installing some Laravel project. How is your answer related to it?
  • XedinUnknown
    XedinUnknown over 4 years
    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.
  • DevonDahon
    DevonDahon over 4 years
    I replaced top by htop, more convenient.
  • Gennadiy Bilyk
    Gennadiy Bilyk over 4 years
    And using df -h. I got this about physical memory was full.
  • Hari Harker
    Hari Harker almost 4 years
    Also look into creating swap file
  • dheeraj
    dheeraj almost 4 years
    It's best to run thosw commands in root model. ``` sudo su```
  • Shawn Pivonka
    Shawn Pivonka over 3 years
    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.
  • Shawn Pivonka
    Shawn Pivonka over 3 years
    For local development for sure go with @Balmipor's Answer, or any other server with a small amount of ram.
  • Balmipour
    Balmipour over 3 years
    @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.
  • Shawn Pivonka
    Shawn Pivonka over 3 years
    @Balmipour 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.
  • Kaushik shrimali
    Kaushik shrimali over 3 years
    Andreas, Solved by up memory limit from php.ini
  • Farhan Ibn Wahid
    Farhan Ibn Wahid over 3 years
    please specify what does this code do and where to apply... @Ali
  • AsTeR
    AsTeR about 3 years
    In case you were like me, even if the memory limit is sky high check still your machine / container max memory.
  • Kirit Patel
    Kirit Patel about 3 years
    I was in troubling since last 4 days and finally has fixed by the "composer dump-autoload --optimize". thanks!. you saved me.
  • Lucas Basquerotto
    Lucas Basquerotto about 3 years
    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.
  • Stef Van Looveren
    Stef Van Looveren almost 3 years
    Swapfile did the trick for me too: stefvanlooveren.me/blog/…
  • Balmipour
    Balmipour almost 3 years
    @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 :)
  • Asad Iftikhar
    Asad Iftikhar over 2 years
    after stoping mysql services, it works for me. Thanks @alirobe
  • Jorge Ribeiro
    Jorge Ribeiro over 2 years
    Increased my Swap from 1GB to 2GB and it worked!
  • PatricNox
    PatricNox about 2 years
    The docker ram increase was the key!