PHP Fatal error when trying to install wp-cli with Homebrew - composer-php

Here is the situation, I'm trying to install wp-cli with Homebrew as following:
brew install wp-cli
But during the installation process, the following error occurs:
PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried
to allocate 29889 bytes) in Unknown on line 0
Homebrew first download the appropriate package:
==> Downloading https://github.com/wp-cli/wp-cli/archive/v0.18.0.tar.gz
And then the process use Composer to proceed the installation:
==> /usr/local/bin/composer install
That causes the above PHP Error and I haven't find any solution to fix this problem (I followed the instructions described here but no success).
I understand the error message and tried to increase the memory limit in the php.ini file (I also tried 1G):
memory_limit = 512M
But without any success even after having restarted the server in order to be sure that my modification was taken into account.
Here are some information about my configuration:
> php -v
PHP 5.5.23 (cli) (built: Mar 23 2015 01:47:37)
> brew -v
Homebrew 0.9.5
> composer -v
Composer version 1.0-dev (f10c71475167a4661225b14560ca0a400d730829) 2015-03-29 14:37:42
> php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File: /usr/local/etc/php/5.5/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d
Additional .ini files parsed: /usr/local/etc/php/5.5/conf.d/ext-mcrypt.ini
Thinking about a memory overload, I also cleaned the cache of Composer with the following command (because error message occurs during the composer install process):
> composer clearcache
That was still useless in my situation, of course every used tools are up-to-date:
> brew update
> brew upgrade
> composer selfupdate
I probably missed something simple but I didn't find the cause of my problem.

Related

Composer Timeout When Extracting Archive

I've recently run into an issue when running composer install. Specially when installing the phpunit/phpunit library. I've tried clearing the composer cache, removing the vendor folder, reinstalling my dev environment, running the command with elevated privileges, and increasing the timeout but nothing seems to be working.
Specially, when I run composer create-project or composer install all the packages are downloaded and installed without issue. But when it gets to phpunit/phpunit it hangs during extraction and eventually times out, with following error
Install of phpunit/phpunit failed
The following exception is caused by a process timeout
[Symfony\Component\Process\Exception\ProcessTimedOutException]
The process "'/usr/local/bin/unzip' -qq '/home/vagrant/code/sites/*****/vendor/composer/tmp-9621203db1563
410535b21d5fa51d984' -d '/home/vagrant/code/sites/*****/vendor/composer/ee7cafdb'" exceeded the timeout o
f 300 seconds.
I have been able to run this command many times in the past, without any problem, this is only a recent issue.
My current dev environment is:
VirtualBox: 6.1.32
Vagrant: 2.2.19
Homestead: laravel/homestead (virtualbox, 12.0.0)
Composer: 2.25
Windows: 11
Any help is much appreciated. I've been stuck on this problem for nearly two days now, with no luck.

Laravel sail / composer require: chmod (directory attributes) error: Operation not permitted

I'm trying to run composer with Laravel Sail but getting errors:
$ sail composer require laravel/passport
Using version [32m^10.1[39m for [32mlaravel/passport[39m
[32m./composer.json has been updated[39m
[32mRunning composer update laravel/passport[39m
[32mLoading composer repositories with package information[39m
[32mUpdating dependencies[39m
[32mLock file operations: 13 installs, 0 updates, 0 removals[39m
- Locking [32mdefuse/php-encryption[39m ([33mv2.2.1[39m)
- Locking [32mfirebase/php-jwt[39m ([33mv5.2.1[39m)
- Locking [32mlaravel/passport[39m ([33mv10.1.0[39m)
- Locking [32mlcobucci/clock[39m ([33m2.0.0[39m)
- Locking [32mlcobucci/jwt[39m ([33m4.1.1[39m)
- Locking [32mleague/event[39m ([33m2.2.0[39m)
.
.
.
- Installing [32mlcobucci/jwt[39m ([33m4.1.1[39m): Extracting archive
- Installing [32mparagonie/random_compat[39m ([33mv9.99.100[39m): Extracting archive
- Installing [32mdefuse/php-encryption[39m ([33mv2.2.1[39m): Extracting archive
- Installing [32mleague/oauth2-server[39m ([33m8.2.4[39m): Extracting archive
- Installing [32mfirebase/php-jwt[39m ([33mv5.2.1[39m): Extracting archive
- Installing [32mlaravel/passport[39m ([33mv10.1.0[39m): Extracting archive
0/13 [>---------------------------] 0% [30;43mFailed to extract lcobucci/clock: (1) unzip -qq '/var/www/html/vendor/composer/tmp-252368372558a177ddb259c3ca81856b' -d '/var/www/html/vendor/composer/29d600e9'
chmod (directory attributes) error: Operation not permitted
fchmod (file attributes) error: Operation not permitted
warning: cannot set modif./access times for /var/www/html/vendor/composer/43c7b0b4/laravel-passport-c2b93a7/LICENSE.md
Operation not permitted
fchmod (file attributes) error: Operation not permitted
warning: cannot set modif./access times for /var/www/html/vendor/composer/43c7b0b4/laravel-passport-c2b93a7/README.md
Operation not permitted
.
.
.
warning: cannot set permissions for /var/www/html/vendor/composer/43c7b0b4/laravel-passport-c2b93a7/config/
Operation not permitted
warning: set times/attribs failed for /var/www/html/vendor/composer/43c7b0b4/laravel-passport-c2b93a7/config/
warning: cannot set modif./access times for /var/www/html/vendor/composer/43c7b0b4/laravel-passport-c2b93a7/
Operation not permitted
warning: cannot set permissions for /var/www/html/vendor/composer/43c7b0b4/laravel-passport-c2b93a7/
Operation not permitted
warning: set times/attribs failed for /var/www/html/vendor/composer/43c7b0b4/laravel-passport-c2b93a7/
[39;49m
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class
[37;41mInstall of laravel/passport failed[39;49m
I've basically just followed the docs for installation, then proceeded to try and install a package. Can't find anything specific to Sail online with this error. Any ideas?
Full Disk Access to Terminal from Security & Privacy fixed my issue.
I ran into exactly the same problem while trying to install Laravel Breeze in a Docker container using the sail command.
Simply run this command in your application directory within your Docker container first:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
The command installs all the latest required composer dependencies and updates your composer file without any of the file restrictions you encountered. In my case, it automatically ran sail composer require laravel/breeze --dev command for me without me having to run it manually.
After that, I only needed to run
sail artisan breeze:install
sail npm install
sail npm run dev
in order.
You can see more details in the Laravel documentation here.
Worked to fix the same issue for me:
./vendor/bin/sail up -d
For me, it was caused by enabling VirtioFS in Docker Desktop 4.6.0 for Mac. I had to disable it and go back to previous driver. However, there're working on it, so probably it'll be fixed in the near future.
In WSL, I was able to solve the problem by enabling chmod.
Please refer to the following issue for instructions.
https://github.com/Microsoft/WSL/issues/81#issuecomment-796798258

PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted [duplicate]

I am trying to add HWIOAuthBundle to my project by running the below command.
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
HWIOAuthBundle github: https://github.com/hwi/HWIOAuthBundle
When I try to run composer require I am getting the out of memory error.
Using version ^0.6.0#dev for hwi/oauth-bundle Using version ^1.2#dev
for php-http/guzzle6-adapter Using version ^1.10#dev for
php-http/httplug-bundle ./composer.json has been updated Loading
composer repositories with package information Updating dependencies
(including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
(tried to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried
to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
I tried setting the memory_limit to 2G in my php.ini file but did not work. I found my php.ini by running php -i | grep php.ini
To get the current memory_limit value, run:
php -r "echo ini_get('memory_limit').PHP_EOL;"
Try increasing the limit in your php.ini file (ex. /etc/php5/cli/php.ini for Debian-like systems):
; Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Or, you can increase the limit with a command-line argument:
php -d memory_limit=-1 composer.phar require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
To get loaded php.ini files location try:
php --ini
Another quick solution:
php composer.phar COMPOSER_MEMORY_LIMIT=-1 require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Or just:
COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
In my case I was trying to require this package when I got this error.
You can run like this, and you don't have to update the PHP INI file:
COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel
Another solution from the manual:
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or in my case
export COMPOSER_MEMORY_LIMIT=-1
composer <...>
Same problem, none of anything related to "memory_limit" worked, but..
composer self-update --2
..solved my problem. (upgrade: 1.10.17 -> 2.0.4)
On Windows 10;
Goto C:\ProgramData\ComposerSetup\bin
Edit: composer.bat and add memory_limit=-1 in the last line as shown below.
#echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
php -d memory_limit=-1 "%~dp0composer.phar" %*
Problem solved ;)
Since none of the previous answers included set it took me a bit to figure out how to do it in Windows without altering the php.ini, but here's what worked for me:
set COMPOSER_MEMORY_LIMIT=-1
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
I have bypassed the problem in a Homestead Laravel (vagrant) virtual machine running the composer commands preceded by COMPOSER_MEMORY_LIMIT=-1:
Examples
To update Composer:
COMPOSER_MEMORY_LIMIT=-1 composer update
To install a package:
COMPOSER_MEMORY_LIMIT=-1 composer require spatie/laravel-translatable
For this error in macOS Catalina and macOS Big Sur use this line:
php -d memory_limit=-1 /usr/local/bin/composer update --no-plugins
I used this line to update on Symfony 5. This command also worked with laravel 7.
Just set the memory_limit specifying the full route of your composer.phar file and update, in my case with the command:
php -d memory_limit=-1 C:/wamp64/composer.phar update
Sometimes the problem is in the composer memory limit. In my case, I tried increasing the php memory limit but still got the error.
You can use COMPOSER_MEMORY_LIMIT=-1 to get around that.
Use it as a prefix:
COMPOSER_MEMORY_LIMIT=-1 composer require the/library
You have to prefix it again in the future.
Hope this helps.
It was recently identified that Composer consumes high CPU + memory on packages that have a lot of historical tags. See composer/composer#7577
A workaround to this problem is using symfony/flex or https://github.com/rubenrua/symfony-clean-tags-composer-plugin
composer global require rubenrua/symfony-clean-tags-composer-plugin
Just in case you get a composer error with:
Could not open input file: composer
run:
php -d memory_limit=-1 /usr/local/bin/composer require ...
For skipping memory limit and version error use the code below:
COMPOSER_MEMORY_LIMIT=-1 composer require <package-name> --ignore-platform-reqs
what about windows?
i use windows 10 and this command worked for me,
php -d memory_limit=-1 "C:\ProgramData\ComposerSetup\bin\composer.phar" update
Composer 2.0 preview is available now: https://github.com/composer/composer/releases
Fixed issue for me. You can set up a preview with composer self-update --preview
EDIT: Composer 2 with memory tuning released
For me, this works on shared hosting.
COMPOSER_MEMORY_LIMIT=-1 composer update
You can use a specific php Version when running Composer
If, like me, for some reason, you are using PHP 32 bits even though your computer is 64 bits, this will always limit the amount of memory allocated to Composer. I solved my problem this way:
Install a 64 bits php version somewhere on your computer (let's say in C:/php64)
In composer (using cygwin in my case), run:
COMPOSER_MEMORY_LIMIT=-1 C:/php64/php.exe ../composer.phar update
in windows by xampp i just changed:
;memory_limit=512M
in php.ini to:
memory_limit =-1
then restart the Apache by xampp
this is the result:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit =-1
;memory_limit=512M
On Mac php 7.4
run
php --ini
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
If Additional .ini files parsed:
memory_limit needs to be changed in
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
As Jose Seie writes, set memory to
memory_limit = -1 or memory_limit = 1G
Just want to share my situation on this matter.
Problem context:
Running composer in a vagrant box.
Was getting this message after try to run composer require "laravel-doctrine/orm:~1.4.13":
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
Have tried setting php.ini memory limit to -1. (still not working).
Solution:
Apparently my composer.json and composer.lock has some issues.
Ran $ composer validate, and the result was:
"The lock file is not up to date with the latest changes in composer.json, it is recommended that you run composer update."
So I ran $ composer update, and all dependencies are resolved. Imho, when the dependencies has some issues, maybe the tree building is out of sync, hence the out of memory issue.
Hope this helps anyone out there.
To override this and fix the issue on your local machine you can do the following changes within your php.ini configuration file.
To locate your php.ini configuration file you can use the following command: php --ini
After running this command you should see an output like the following:
Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File: /usr/local/etc/php/7.3/php.ini <---- note the path
Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.3/conf.d/ext-opcache.ini
The file we want to change is the Loaded Configuration.
Open and search for the memory_limit you can set the memory_limit = -1 to give an unlimited amount of memory to PHP processes or you can set 512MB, 1G, 2G, 5G,....
$ nano /usr/local/etc/php/7.3/php.ini
locate and set:
$ memory_limit = -1 or memory_limit = 1G
After saving your file, you can verify the PHP changes by running this command which will output the current memory settings in your php.ini file:
php -r "echo ini_get('memory_limit').PHP_EOL;"
NOTE:
After saving, the new memory will be working. You don't need to do anything else.
More info: https://support.acquia.com/hc/en-us/articles/360036102614-Overriding-memory-limits-during-local-development-with-Composer
for Centos 7 use :
COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52 Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
set memory_limit to -1 works for me ;) (vim /etc/php/7.2/cli/php.ini)
For Macbook:
run command sudo nano ~/.bash_profile to edit bash_profile then add alias composer="COMPOSER_MEMORY_LIMIT=-1 composer" in that file, then save and exit.
Hope this will solve the problem; Happy coding!
I condensed or packaged up the useful and accepted answer here into reusable (zsh) aliases/functions, for quicker and easier-to-remember reuse:
# composer high-memory
composermem() {
php -r "echo ini_get('memory_limit').PHP_EOL;"
}
alias composerbig='COMPOSER_MEMORY_LIMIT=-1 composer $1'
(php composer.phar is already aliased to composer on the system).
I solved this problem using this command COMPOSER_MEMORY_LIMIT=-1
Example: COMPOSER_MEMORY_LIMIT=-1 composer requires larval/ui
the options on this page worked for me
https://www.jesusamieiro.com/php-fatal-error-allowed-memory-size-of-1610612736-bytes-exhausted/
To be more precise solution one:
COMPOSER_MEMORY_LIMIT=-1 composer update
Make sure to not require a package before making sure the vendor folder exists.
Check if you have done composer install before. You may be just cloned the repository to your machine. So, you have to install the old packages before requiring a new one. Or you may want to include this option --profile to your composer command to see the timing and memory usage information.
In my case:
Windows 10 and Docker Desktop works:
docker-compose -f .docker/docker-compose.yml exec php env COMPOSER_MEMORY_LIMIT=-1 composer require fideloper/proxy
You just need to increase memory limit on "php.ini" file to solve the problem
find the "memory_limit" in php.ini file.
just change memory_limit value to 2G like below
;http://php.net/memory-limit
memory_limit=2G
to relocate the php file by using below command.
php --ini

Cannot update Composer's memory size

I'm trying to install an extension on Magento 2 via Composer, but when I run Composer update, I get the following error:
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
I try:
php -d memory_limit=-1 composer update
But I get:
Could not open input file: composer
So I tried and got:
curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 1.9.0) successfully installed to: /home/customer/www/xxx/public_html/composer.phar
Use it: php composer.phar
So, thinking it's fixed I again tried and got:
php -d memory_limit=-1 composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
So I tried composer update again and got:
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
So again, I try composer update and get
Could not open input file: composer
I'm right back to where I started and incredibly confused :/ Please advise. Thank you.
When you are using php -d memory_limit=-1 you are setting an ini entry on the fly but only for the script run via that command.
Your idea to run this command was close to what you want to achieve:
php -d memory_limit=-1 composer update
The only thing you have to know is the fact that composer works as a command because it stands somewhere your OS would look for all the executables (most likely /usr/bin/composer, /usr/local/bin/composer, or something the like, this is usually referenced as the PATH). But when you try to run php composer, then composer is just considered as a regular file, and your OS do not try to look in your executable path anymore.
What you can do still is to use the command which, that will return you the path to that composer executable.
$ php $(which composer) -V
Composer version 1.8.6 2019-06-11 15:03:05
So you should be able to achieve what you aim to do via
php -d memory_limit=-1 $(which composer) install
for installation of packages; and
php -d memory_limit=-1 $(which composer) update
for updates.
Please also mind that: there is a full article in the composer documentation about memory limit: https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors
That could possibly ease you job, changing the relevant PHP CLI setting, or that could point you at the usage of
COMPOSER_MEMORY_LIMIT=-1 composer install
and
COMPOSER_MEMORY_LIMIT=-1 composer update

Composer install log location on Ubuntu

I am trying to install Drupal's OpenEdu project on Ubuntu 16.04 with composer by running the following command:
composer create-project imagex/openedu-project openedu
This produces a load of messages pertaining to PHP settings, and the project is not installed. The problem is that I cannot see all the messages on the screen (VMware console), only the last x lines.
The question is: where can I see the full result of the attempt at creation of the project?
You can redirect composer output to file:
composer create-project imagex/openedu-project openedu --no-interaction --no-progress > install.log 2>&1
And then use less to browse the file:
less install.log

Resources