WP-CLI over SSH: updating and fixing WordPress from the command line

The short answer: WP-CLI is WordPress on the command line. Instead of opening the dashboard and clicking, you type wp plugin update --all and it is done. On our hosting servers the wp command is already installed for accounts with SSH access: you do not need to install anything.

We checked on the server: the command exists and is the WP-CLI that ships with the WordPress tool in cPanel (version 2.12.0 when we measured it). You need an account with SSH or the cPanel Terminal. Not every account has command-line access: it depends on the account. How to log in is in SSH access.

Before the first command

1 Take a backup. These commands change files and the database. What to copy is in what to back up before updating. A quick database copy is wp db export copy.sql.
2 Go to the site folder, the one containing wp-config.php. From any other folder, say where it is with --path=/path/to/site.
3 Confirm with two commands: wp core version prints the WordPress version and wp --info shows, among other things, the PHP the command will use.
4 The PHP may not be the one your site uses. WP-CLI uses the account’s command-line PHP. To use another one, call it on purpose, for example /opt/alt/php82/usr/bin/php /usr/local/bin/wp --version. The case is explained in the SSH PHP version.

The commands you will use most

To do this Command Note
See whether a new WordPress version exists wp core check-update Only shows. Changes nothing.
Update WordPress wp core update Back up first. See Updating WordPress.
Check whether WordPress files were altered wp core verify-checksums Compares them with the official files. Useful after a security problem.
List plugins, showing the ones with an update wp plugin list --update=available Without the option it lists all of them.
Update every plugin wp plugin update --all If a plugin breaks the site, the next command helps.
Deactivate a plugin without the dashboard wp plugin deactivate plugin-name The name is the “name” column of wp plugin list. See Disabling plugins.
Swap an address across the whole database wp search-replace 'https://old' 'https://new' --dry-run With --dry-run it only shows what would change. Repeat without it to apply. See Moving WordPress to a new domain.
Rebuild the permanent links wp rewrite flush When pages return 404 after a change.
Run overdue scheduled tasks wp cron event run --due-now See Swapping WP-Cron for a real cron job.
Never type a password on the command line. Whatever you type stays in the shell history. To reset a user’s password use the WordPress recovery e-mail or the WordPress dashboard.
Look before you act: --dry-run wherever it exists, and wp plugin list --update=available before wp plugin update --all. If you prefer a screen, the WordPress tool in cPanel does the same: The WordPress tool in cPanel.

WP-CLI is third-party software and the commands are yours. If one goes wrong, the way back is restoring the backup. How far our support goes is in How far our support goes.

A command returned an error you do not understand? Open a ticket with the command and the full reply.

Open a support ticket

SEE ALSO

SSH access on your hosting account

The WordPress tool in cPanel

What to back up before you update WordPress, plugins or PHP

Disabling plugins, including when you cannot get in

RECOMMENDED PRODUCT

WordPress hosting

One-click install, updates handled, and speed that holds up. from $6.60/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?