Local Community

WP CLI Not Working for a Site

I’m using Local Lightning (5.0.7+1117) on macOS 10.15.2 (19C57). I just created a new site, and the WP CLI is always returning “Error: Error establishing a database connection.” I’m using the wp-cli.local method of the CLI, in part because I have wp on my Mac anyway, and in part because I’m using the Fish shell, so the Open Site SSH doesn’t work for me. I’ve double-checked that the host in the wp-cli.local.php file is the correct socket (and the site loads fine in a web browser, as does the DB in Sequel Pro with the same socket path), yet the CLI still returns the DB error. I’ve tested this with both my Homebrew-installed wp (2.4.0) and the copy shipped in Local (2.2.0), both encounter the same error. I’ve seen this on another, older, local site, as well, though one other site is working fine. I can use the WP-CLI to access remote installations and it works just fine. Maybe macOS 10.15.2 introduced some problem with using sockets on the command line? Does anyone have any advice about how to get the WP CLI to work in Local again?

Figured it out myself, there was a mismatch in PHP versions.

@alexclst can you elaborate at all on what you did to get it working… Does the PHP version in Local need to be the same on on your computer?

@helgatheviking I had a version of PHP installed via Homebrew that was significantly different from what was provided with Local. The WP CLI on my Mac was linked to the Homebrew version of PHP, with the site running using Local’s version. This meant that the CLI could not properly communicate with the Local site. It was fixed by simply ensuring that Homebrew installed the same version that Local was using.

Thanks!! I think there was also a bug in WP-CLI itself that I think has since been resolved (and updated in local)

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