Fix Fatal error when installing a WP-CLI package

Fix Fatal error when installing a wp-cli package

My setup: bash as my terminal profile, running MAMP PRO for local development. The MAMP PRO part was key to fixing the fatal error issue for me.

TL;DR Composer was using an outdated PHP, while my server was running the latest. Need them to use the same PHP version. Instructions below.

Fatal Error output screenshot for WP-CLI

While attempting to install the wp admin package for WP-CLI, i kept getting an error similar to this:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2015232 bytes) in phar:///usr/local/Cellar/wp-cli/1.5.0/libexec/wp-cli-1.5.0.phar/vendor/composer/composer/src/Composer/Cache.php on line 99
Reverted composer.json.

An expanded command line output throughout this process is at the bottom of the post for reference.

Things i tried:

  • Ensured WP-CLI was the latest version — wp cli update
  • Increasing the memory limit in WordPress by adding this to the wp-config.php file — define(WP_MEMORY_LIMIT, "512M");
  • You can instead use WP-CLI to do the above — wp config set WP_MEMORY_LIMIT "512M"
  • Increasing the memory limit for PHP by adding memory_limit = 512M to my php.ini file.
  • I updated the outdated Composer to the latest version — composer self-update.

Finally got some where by running Composer diagnostics — composer diagnose — and seeing if the PHP version it used was the same as the PHP running on my local server.

First do php -v to see what version of PHP you’re running.

PHP 7.3.0 (cli) (built: Jan  2 2019 12:47:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies

Then do composer diagnose to see if Composer matches.

PHP version: 7.1.23
PHP binary path: /usr/bin/php

You see that Composer is using 7.1.23, but PHP is 7.3.0. If there’s a PHP mismatch, change the PHP binary path to use the path PHP is using.

In my case, since i’m running MAMP PRO, i had to specify the correct MAMP PRO path, rather than the path that php -v was showing.

I’m assuming your terminal of choice is bash, so you’ll need to append your ~/.bash_profile with a line at the end.

export PATH="/Applications/MAMP/bin/php/php7.3.0/bin:$PATH"

Now let terminal know that you’ve updated your ~/.bash_profile with the source ~/.bash_profile command.

I suggest running composer diagnose again to verify the PHP versions are aligned.

Now try installing wp admin via wp package install wp-cli/admin-command once more. Hopefully, no more errors pop up. My full output is below.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2015232 bytes) in phar:///usr/local/Cellar/wp-cli/1.5.0/libexec/wp-cli-1.5.0.phar/vendor/composer/composer/src/Composer/Cache.php on line 99
Reverted composer.json.
WP-CLI ran out of memory. Please see https://bit.ly/wpclimem for further help.
Sat Aug 31 11:34:40 [[email protected] blog]$ composer diagnose
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.9.0
PHP version: 7.1.23
PHP binary path: /usr/bin/php
Sat Aug 31 11:34:54 [[email protected] blog]$ which php
/usr/bin/php
Sat Aug 31 11:35:05 [[email protected] blog]$ source ~/.bash_profile
Sat Aug 31 11:35:20 [[email protected] blog]$ which php
/Applications/MAMP/bin/php/php7.3.0/bin/php
Sat Aug 31 11:35:23 [[email protected] blog]$ composer diagnose
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.9.0
PHP version: 7.3.0
PHP binary path: /Applications/MAMP/bin/php/php7.3.0/bin/php
Sat Aug 31 11:35:38 [[email protected] blog]$ wp package install wp-cli/admin-command
Installing package wp-cli/admin-command (dev-master)
Updating /Users/mjames/.wp-cli/packages/composer.json to require the package...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.051 seconds
Analyzed 1415 packages to resolve dependencies
Analyzed 39353 rules to resolve dependencies
Package operations: 1 install, 0 updates, 0 removals
Installs: wp-cli/admin-command:dev-master 66f0370
 - Installing wp-cli/admin-command (dev-master 66f0370)
Writing lock file
Generating autoload files
---
Success: Package installed.

If you run across anything weird, please comment on the post. Thanks! Cheers and peace.

If you found this post useful ...

Buy Me a Coffee logo
Wondering why you keep seeing lower-cased 'i' in my posts? Read -> Why ‘i’ is not capitalized