Local Community

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!