Wp-cli globally installed don't work: error connecting to db host

Here my situation:

  • I’m using Bedrock with it’s structure untouched;
  • Using Laravel Homestead because it’s simple and fast to run and serves well for all my site;
  • wp-cli.yml is just like this: path: web/wp
  • Installed wp-cli globally via Homebrew;
  • Run wp
  • Gets the error: Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /Users/myname/project/web/wp/wp-includes/wp-db.php on line 1538 Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localhost`. This could mean your host’s database server is down;
  • It’s not down, in fact I’m running in my browser while I’m trying;
  • Can’t figure out what to do to make it work;
  • Got frustrated;

You’re trying to use WP-CLI from your host machine, not on the VM. That’s not possible unless you setup aliases for your Vagrant box.

You need to SSH into your Homestead box, install WP-CLI on there, and use WP-CLI from there.

Trellis provides a notice about that upon vagrant up :wink:

1 Like

Damn it. It was really it .-.

Thank you @ben!