You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WP-CLI aliases are shortcuts you register in your `wp-cli.yml` or `config.yml` to effortlessly run commands against any WordPress install.
35
+
36
+
For instance, if I'm working locally on the runcommand theme, have registered a new rewrite rule, and need to flush rewrites inside my Vagrant-based virtual machine, I can run:
37
+
38
+
$ wp @dev rewrite flush
39
+
Success: Rewrite rules flushed.
40
+
41
+
Then, once the code goes to production, I can run:
42
+
43
+
$ wp @prod rewrite flush
44
+
Success: Rewrite rules flushed.
45
+
46
+
Look ma! No more SSH'ing into machines, changing directories, and generally spending a full minute to get to a given WordPress install.
47
+
48
+
Additionally, alias groups let you register groups of aliases. If I want to run a command against both runcommand WordPress instances, I can use `@both`:
49
+
50
+
$ wp @both core check-update
51
+
Success: WordPress is at the latest version.
52
+
Success: WordPress is at the latest version.
53
+
54
+
Aliases can be registered in your project's `wp-cli.yml` file, or your user's global `~/.wp-cli/config.yml` file:
55
+
56
+
@prod:
57
+
ssh: runcommand@runcommand.io~/webapps/production
58
+
@dev:
59
+
ssh: vagrant@192.168.50.10/srv/www/runcommand.dev
60
+
@both:
61
+
- @prod
62
+
- @dev
63
+
64
+
#### But wait, what's the 'ssh' in there?
65
+
66
+
WP-CLI now natively supports a `--ssh=<host>` global parameter for running a command against a remote WordPress install. Many thanks to XWP and their community for paving the way with [WP-CLI SSH](https://github.com/xwp/wp-cli-ssh).
67
+
68
+
Under the hood, WP-CLI proxies commands to the `ssh` executable, which then passes them to WP-CLI installed on the remote machine. Your syntax for `-ssh=<host>` can be any of the following:
69
+
70
+
* Just the host (e.g. `wp --ssh=runcommand.io`), which means the user will be inferred from your current system user, and the path will be the SSH user's home directory.
71
+
* The user and the host (e.g. `wp --ssh=runcommand@runcommand.io`).
72
+
* The user, the host, and the path to the WordPress install (e.g. `wp --ssh=runcommand@runcommand.io~/webapps/production`). The path comes immediately after the TLD of the host.
73
+
74
+
Or, if you use a `~/.ssh/config`, `<host>` can be any host alias stored in the SSH config (e.g. `wp --ssh=rc` for me).
75
+
76
+
Note you do need a copy of WP-CLI on the remote server, accessible as `wp`. Futhermore, `--ssh=<host>` won't load your `.bash_profile` if you have a shell alias defined, or are extending the `$PATH` environment variable. If this affects you, [here's a more thorough explanation](https://runcommand.io/to/wp-ssh-custom-path/) of how you can make `wp` accessible.
0 commit comments