Problem with WP CLI

Issue Summary

When trying to run the wp post create wp-cli command in my local Site Shell I get the following error:

Fatal error: Cannot declare class WP_CLI, because the name is already in use in phar:///Applications/Local.app/Contents/Resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/class-wp-cli.php on line 26

I have checked and I don’t have any other install of wp cli on my local. When I run wp --info I get:

OS:	Darwin 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64
Shell:	/usr/local/bin/zsh
PHP binary:	/Users/etienne/Library/Application Support/Local/lightning-services/php-8.0.0+2/bin/darwin/bin/php
PHP version:	8.0.0
php.ini used:	/Users/etienne/Library/Application Support/Local/run/wL7PYIX6z/conf/php/php.ini
MySQL binary:	/Users/etienne/Library/Application Support/Local/lightning-services/mysql-5.7.28+5/bin/darwin/bin/mysql
MySQL version:	mysql  Ver 14.14 Distrib 5.7.28, for macos10.14 (x86_64) using  EditLine wrapper
SQL modes:	ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/etienne/Desktop/Studio DPE/Clients/WOW/Les Bottés/Local/app/public
WP-CLI packages dir:	
WP-CLI global config:	/Applications/Local.app/Contents/Resources/extraResources/bin/wp-cli/config.yaml
WP-CLI project config:	
WP-CLI version:	2.5.0

I have even tried updating the wp-cli.phar but it doesn’t solve the issue.

Troubleshooting Questions

  • Does this happen for all sites in Local, or just one in particular?
    On all websites

System Details

  • Which version of Local is being used?
    6.3.0

  • What Operating System (OS) and OS version is being used?
    macOS Monterey 12.2.1

  • Local Logs
    local-logs.zip (222.1 KB)

Hello @epigeyre

Could you please suggest, how you fixed the above issue? I am facing the same problem after updating my system.

Thanks in advance!

I had the exact same problem, though it intermittently worked. I fixed it by disabling the opcache for cli (which is the PHP default anyway).

Make sure your site is stopped. In Local select your site and click “Go to site folder”, navigate to conf\php, and edit php.ini.hbs to comment out the opcache.enable_cli line

; opcache.enable_cli=1

Start the site to regenerate the php.ini

Should work from now on

Hello @ankitguptaindia,

I didn’t found any solution, I just ended up not using WP CLI for what I wanted to do. However, I’ve just tested @dave_slaughter solution and it works perfectly for me :).

Thanks!

Hey @dave_slaughter

Thanks for the solution. It fixed my WP CLI problem. You are Great :tada:

Thanks for the response @epigeyre ! Yes, that fixed my problem too.

Hi! I stumbled on the same problem after updating to version 6.4.1 today.

This workaround with disabling the opcache for CLI worked for me too.

Still would like to know why this is no longer working normally anymore, especially after updates.

Thanks,
Ruud

Hi @ankitguptaindia @epigeyre @dave_slaughter;

Contrary to what I wrote just minutes ago, I did find another solution.

I recently had another issue with the site being very slow, and managed to get it working normally again by changing some other things, see:

In the second part of that message I also made additions to the way wp-cli starts (I think):

@ECHO OFF
php "%~dp0\..\wp-cli.phar" %*

to

@ECHO OFF
php -dxdebug.mode=debug "%~dp0\..\wp-cli.phar" %*

For me the shell works without disabling the opcache.enable_cli=1 line

Hope this helps,
Ruud

2 Likes

The problem still persists with version 6.4.2.

Current workaround:

The locations for these 2 batch files are:

  1. /Users/{username}/Appdata/Local/Programs/Local/resources/extraResources/bin/wp-cli/win32/wp.bat
  2. /Users/{username}/Appdata/Local/Programs/Local/resources/extraResources/bin/composer/win32/composer.bat

The changes are to add -dxdebug.mode=debug like in this example:

The other issue (LocalWP app itself is no longer able to retrieve the WP version from the site) seems fixed at this time.

@ECHO OFF
php -dxdebug.mode=debug “%~dp0…\wp-cli.phar” %*

The problem still persists with version 6.4.3.

The workaround for version 6.4.2 works

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.