brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: aliases in wp-cli.yml run wp commands on a remote site over ssh

Network and access
~/tips/tip-wordpress-wp-cli-yml-ssh-alias

@prod:

Gives a remote WordPress site a short name so wp commands run over ssh as wp @prod.

Logging in to a server just to run one wp command gets old quickly. WP-CLI can do the ssh part for you, and an alias gives the site a short name.

Put this in wp-cli.yml in your project, or in ~/.wp-cli/config.yml for all projects:

@prod:
  ssh: [email protected]~/webapps/production
@staging:
  ssh: [email protected]/var/www/staging

The part after the host is the WordPress path on the remote machine. Then put the alias right after wp:

wp @prod core check-update
wp @staging plugin list --update=available

You can also skip the file and pass the host directly with wp --ssh=example.com:2222 option get home. A group alias is a list of other aliases, so one command can hit several sites.

Caveats from the handbook: WP-CLI has to be installed on the remote server and be reachable as wp. Ssh does not load your ~/.bashrc or ~/.zshrc for these commands, so if the remote shell cannot find wp, you may have to fix the $PATH for non-interactive logins. Some hosts also block this kind of access.

Because the command runs on the live site, be careful with anything that writes. Run the read-only version first.

Further reading: Running commands remotely (WP-CLI handbook)

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link