I am running the most recent version of WP-CLI on my mac. I do all WordPress development within Vagrant, but would like to run WP-CLI commands in the host machine. I have a domain alias from “dev.mysite.com” to the IP of my server so it can be accessed through my web browser through an HTTP request.

When trying to run a WP-CLI command, I get an “Error Establishing a Databse Connection” error mesage because it is trying to connect via “localhost” when it really should be “dev.mystie.com” or the Vagrant VM’s IP Address. Is there any way I can access my site through WP-CLI without having to SSH into the guest?

4 s
4

Since the issue is probably DB configuration you could try adjusting it conditionally in wp-config.php:

if ( defined( 'WP_CLI' ) ) {
    define( 'DB_HOST', 'example.com' );
}
else {
    define( 'DB_HOST', 'localhost' );
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *