WP-CLI support with MySQL sockets in Local 5

So since Local switched to a MySQL socket connection I’m unable to get WP-CLI working. WP-CLI tries to connect to the database using the values in wp-config.php, which is “localhost” for the server instead of a socket and throws the Error: Error establishing a database connection. error. Is there any way to support WP-CLI commands with the new socket connection type for MySQL?

I found out how. In wp-config.php change the

define('DB_HOST', 'localhost');


define('DB_HOST', 'localhost:/path/to/the/socket.sock');

and it works :slight_smile:

1 Like

wpcli should be working with the latest (5.x) versions of Local. Are you right-clicking on the site in Local and selecting “Open Site Shell?”

This will open a terminal and configure the various environmental variables that need to be set in order to connect to the correct site.

1 Like

Thanks, Ben.

Just one modification to your instructions is required for those of us who are using Local with Roots Bedrock WordPress.

When using Bedrock with Local, the Bedrock wp directory is in a different location from the standard Local setup, but wp-cli works if I just add the path to Bedrock’s wp directory using the –path parameter as shown below… (the command is being run from the …/app/public directory that Site Shell opens in)…

       wp db tables   --path='../bedrock/web/wp'
1 Like

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