I need to run composer update at my hosting so I log in with ssh and try to run the following command inside /www folder where I have Laravel and composer installation:
composer update
I get this error:
I'm in contact with my hosting provider, they told me to run the command:
php -d memory_limit=512M composer update
I ran this command but I got: "Could not open file: composer"
What to do? What is the solution here?
This question is related to
php
laravel
ssh
composer-php
The best solution for me is
COMPOSER_MEMORY_LIMIT=-1 composer require <package-name>
mentioned by @realtebo
This error can occur especially when you are updating large libraries or libraries with a lot of dependencies. Composer can be quite memory hungry.
Be sure that your composer itself is updated to the latest version:
php composer.phar --self-update
You can increase the memory limit for composer temporarily by adding the composer memory limit environment variable:
COMPOSER_MEMORY_LIMIT=128MB php composer.phar update
Use the format “128M” for megabyte or “2G” for gigabyte. You can use the value “-1” to ignore the memory limit completely.
Another way would be to increase the PHP memory limit:
php -d memory_limit=512M composer.phar update ...
Set it to use as much memory as it wants with:
COMPOSER_MEMORY_LIMIT=-1 composer update
In my case it needed higher permissions along with this memory limit increase.
sudo COMPOSER_MEMORY_LIMIT=2G php /opt/bitnami/php/bin/composer.phar update
I am facing problems with composer because it consumes all the available memory, and then, the process get killed ( actualy, the output message is "Killed")
So, I was looking for a solution to limit composer memory usage.
I tried ( from @Sven answers )
$ php -d memory_limit=512M /usr/local/bin/composer update
But it didn't work because
"Composer internally increases the memory_limit to 1.5G."
-> Thats from composer oficial website.
Then I found a command that works :
$ COMPOSER_MEMORY_LIMIT=512M php composer.phar update
Althought, in my case 512mb is not enough !
Source : https://www.agileana.com/blog/composer-memory-limit-troubleshooting/
I'm running Laravel 6 with Homestead and also ran into this problem. As suggested here in the other answers you can prefix COMPOSER_MEMORY_LIMIT=-1
to a single command and run the command normally. If you'd like to update your PHP config to always allow unlimited memory follow these steps.
vagrant up
vagrant ssh
php --version # 7.4
php --ini # Shows path to the php.ini file that's loaded
cd /etc/php/7.4/cli # your PHP version. Each PHP version has a folder
sudo vi php.ini
Add memory_limit=-1
to your php.ini file. If you're having trouble using Vim or making edits to the php.ini file check this answer about how to edit the php.ini file with Vim. The file should look something like this:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit = -1
Note that this could eat up infinite amount of memory on your machine. Probably not a good idea for production lol. With Laravel Valet had to follow this article and update the memory value here:
sudo vi /usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
Then restart the server with Valet:
valet restart
This answer was also helpful for changing the config with Laravel Valet on Mac so the changes take effect.
You can change the memory_limit
value in your php.ini
Try increasing the limit in your php.ini file
Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Note: Composer internally increases the memory_limit to 1.5G.
Read the documentation getcomposer.org
<C:\>set COMPOSER_MEMORY_LIMIT=-1
<C:\>composer install exhausted/packages
Write this on Homestead.yaml
variables:
- key: COMPOSER_MEMORY_LIMIT
value: -1
I made this on Windows 10 and worked with me:
php -d memory_limit=-1 C:/ProgramData/ComposerSetup/bin/composer.phar update
You can change xx Value that you want
memory_limit=XX
How large is your aws server? If it only has 1gb of ram, setting the memory limit of 2gb in php.ini won't help.
If you can't/don't want to also increase the server side to get more RAM available, you can enable SWAP as well.
See here for how to enable swap. It enables 4gb, although I typically only do 1GB myself.
Source: Got from laracast site
On MAC OS High Siera I ran the below:
MacBook-Pro:asiu jack$ php --ini
Returned:
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-
opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
All answers above are setting the loaded config which does update, but notice additional .ini files parsed has php-memory-limits.ini as a separate file. You have to update this file memeory limit as well. same way open in text editor and change to somehting like 2G. The output on memory limit failure should tell you how much memory it needs to run, just set it to higher than that or -1 for unlimited.
For Laravel
Step 1. Open your terminal
step 2. cd
into your laravel directory
step 3. Type the command which composer
, in your laravel directory and note the directory in which composer resides.
step 4. run the command php -d memory_limit=-1 /opt/cpanel/bin/composer update
(you can also run the code if it works for you)
(change /opt/cpanel/bin/composer
to the directory path returned in step 3 )
Problem solved
php ini
filememory_limit = -1
In my case none of the answers helped. Finally it turned out, that changing to a 64 bit version of PHP (M$ Windows) fixed the problem immediately. I did not change any settings - it just worked.
If there's enough memory composer would internally consume it and run without any problem. No need to specifically tell the composer to do it.
Have you tried to increase your swap memory, coz it worked for me. I increased the swap memory to 4096Mb (4GB) and now it all looks great to me.
first use "sudo free
" to see available memory and swap memory. and configure swap as,
For Debian:
sudo fallocate -l 4G /swapfile
sudo dd if=/dev/zero of=/swapfile bs=4096k count=1048
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
to make it permenant add this to /etc/fstab file, /swapfile swap swap defaults 0 0
For CentOS :
[root@myserver]:/# cd /var
[root@myserver]:/var# touch swap.img
[root@myserver]:/var# chmod 600 swap.img
[root@myserver]:/var# mkswap /var/swap.img
[root@myserver]:/var# dd if=/dev/zero of=/var/swap.img bs=4096k count=1000
[root@myserver]:/var# mkswap /var/swap.img
[root@myserver]:/var# swapon /var/swap.img
you can increase your swap memory by changin bs= 1024k or 2048k or 8096k depending on your physical volume size. use 'swapon' and swapoff commands to see the difference.
check 'swappiness' (60 should do good,)
cat /proc/sys/vm/swappiness
I had to combine COMPOSER_MEMORY_LIMIT
and memory_limit
in the command line:
On Windows:
set COMPOSER_MEMORY_LIMIT=99999999999&& php -d memory_limit=-1 composer.phar update
On Linux:
export COMPOSER_MEMORY_LIMIT=99999999999 && php -d memory_limit=-1 composer.phar update
In Windows 10 (Git bash), i had to use this
php -d memory_limit=-1 C:\\composer\\composer.phar install
Source: Stackoverflow.com