Where is WP-CLI?

Hi!
I’ve been trying to get started with WP-CLI, but I can’t understand how it works. As I have understood it, Trellis comes with WP-CLI. But I don’t know how to do.

I’ve tried to SSH into Trellis and use wp-cli from there, but without success. If I write try to find out which version is installed I see that there is no version installed.
vagrant@demoshop:~$ which wp-cli vagrant@demoshop:~$

I’ve found some files inside of trellis/roles/wp-cli. Shouldn’t this work out of the box after running vagrant up?

The command for WP-CLI is wp and you can find where it’s installed using which wp; this should give you /usr/bin/wp.

http://wp-cli.org/commands/ is a good place to start learning what commands are available and what it does. I use it primarily for exporting and importing databases from environment to environment but it can do quite a lot more.

Thanks for your fast reply! Now I get it.

Still, I have one more question. I’ve started to use PHPStorm, and I really like it with Roots. I’ve configured Gulp, Vagrant and database from PhpStorm, but the last thing I want to control is WP-CLI.

PhpStorm has support for WP-CLI, but I don’t know how to connect it. Since WP-CLI is installed in Trellis, usr/bin/wp, I’m not sure how to point it to the correct path.

Is this possible? Or do I have to install WP-CLI on my local machine?

WP-CLI is installed by Trellis automatically. The wp command is available globally but you need to run the command from your site root such as /srv/www/example.com/current.

So you need to SSH into your Vagrant box or server, go to that directory, and then run wp commands.

@ben is working on a blog post to show how to use https://github.com/xwp/wp-cli-ssh which lets you run WP-CLI commands locally skipping the manual SSH part.

5 Likes

Maybe I should create a new topic for this, but it seems relevant so:

I’m very familiar and comfortable with WP-CLI, but when I’m running wp db export in any of the following folders I’m getting sh: mysqldump: command not found.

It leaves me with the question of “Where is WP-CLI commands suppose to be run?”

You need to be connected to the server running the database to dump the database:

  1. Navigate to your Trellis folder $ cd example.com/trellis
  2. Run vagrant up if the VM isn’t running yet.
  3. SSH to your VM $ vagrant ssh
  4. Now you’re connected to your vagrant VM, change directories to your web root $ cd /srv/www/example.com/current
  5. Export your db$ wp db export
  6. You’ll find the dump file on your local machine in example.com/site
5 Likes

Okay, that makes sense. Thanks.

So why would I get command not found?

vagrant@roots-example-project:/srv/www/testing.my-domain.tk/current$ wp
-bash: wp: command not found

Been using wp-cli locally for ages otherwise, just not vagrant …
Any help appreciated.

1 Like

I am getting same error “-bash: wp: command not found” on existing project, there are a few other posts with this issue, but none seems to have solution to this problem.

@sanjeev please don’t bump multiple topics when looking for help. I’m locking this in favor of the newer topic that was also bumped: