-
Notifications
You must be signed in to change notification settings - Fork 14
Configuring the plugin
This plugin was made to simplify WP-CLI tasks when running your WordPress website on multiple server at the same time.
Let's say you are using Varying-Vagrant-Vagrants to run your website on your local environment and you want to use WP-CLI to send your command to the vagrant box.
Normally those are the steps required to achieve this:
$ cd ~/Sites/vvv/www/example.com/
$ vagrant ssh
$ cd /srv/www/example.com/
$ wp plugin status # this generates your output
$ exit
Not very practical!
With wp-cli-ssh you can automated this with only a few lines of code. Requires wp-cli >= v0.13
- Install WP-CLI-SSH with composer (if you installed WP-CLI to a different location, use it instead of
~/.wp-cli
):
$ cd ~/.wp-cli && composer require x-team/wp-cli-ssh:dev-master
- Add a ssh server to your
wp-cli.local.yml
or yourwp-cli.yml
file:
ssh:
vagrant:
# The %pseudotty% placeholder gets replaced with -t or -T depending on whether you're piping output
# The %cmd% placeholder is replaced with the originally-invoked WP-CLI command
cmd: vagrant ssh-config > /tmp/vagrant_ssh_config && ssh -q %pseudotty% -F /tmp/vagrant_ssh_config default %cmd%
# Passed to WP-CLI on the remote server via --url
url: local-www.yourawesomewebsite.com
# We cd to this path on the remote server before running WP-CLI
path: /your/vvv/path/
- Now you can go to the root of your project and do:
$ wp ssh plugin status --host=vagrant
Voilà!
Bonus:
Tired of writing --host=vagrant
?
You can easily create an alias in ~/.bash_profile
:
alias wpv='wp ssh --host=vagrant' #or some other host
Now you can write your command:
$ wpv plugin status
Hardcore developer bonus:
Want to forward your wp-cli command to some external server that you can only access through a jump server?
Oh my unicorn! We can do that?
Of course! Here is how (in wp-cli.local.yml or your wp-cli.yml file):
ssh:
superjumpserver:
cmd: ssh %pseudotty% jump.example.com ssh %pseudotty% yourservername %cmd%
url: staging-www.yourawesomewebsite.com
path: /your/staging/server/path/
And voilà!
$ wp ssh plugin status --host=superjumpserver