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?
This question is tagged with
~ Asked on 2013-12-18 20:29:02
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:
composer updatein 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.
git pushthe composer.lock file.
composer installon 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.
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.
~ Answered on 2013-12-20 08:29:09
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, 1M * 2000 ~= 2GB of swap memory. Feel free to add MORE dd if=/dev/zero of=swapfile bs=1M count=2000 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.
~ Answered on 2016-01-25 17:41:17