How to use WP-CLI on your hosting
Manage updates, plugins, users and search-and-replace from the command line over SSH, faster than clicking through the dashboard for the same job.
WP-CLI is the official command-line tool for managing WordPress. Anything you can do by clicking through the dashboard, WP-CLI can usually do in a single line — updating plugins, creating users, running a database search-and-replace, or checking which version of WordPress core is installed — and it can do several of them at once in a script, which the dashboard cannot.
What you need
- SSH access to your hosting account. See using SSH on a hosting account if you have not connected before.
- WP-CLI available on the account, either pre-installed or installable in your own directory depending on the hosting environment.
Checking WP-CLI is available
Connect over SSH, move into the folder containing your WordPress install, and run:
wp --info
If this returns version details for WP-CLI, PHP, and your WordPress install, you are ready to go. If the command is not found, check with your host whether it needs enabling for your account or installing manually.
WP-CLI works out which site it is talking to by looking for a wp-config.php file in the current directory. Running a command from the wrong folder either fails outright or, on an account hosting more than one site, risks acting on the wrong one.
Commands worth knowing
Checking versions and status
wp core version
wp plugin list
wp theme list
Updating everything
wp core update
wp plugin update --all
wp theme update --all
This is considerably faster than clicking Update on each item individually in the dashboard, particularly on a site with a large number of plugins. See updating WordPress without breaking your site for the safety practices — taking a backup first, and updating one thing at a time when you specifically want to isolate which update caused a problem — that still apply whether you update through the dashboard or the command line.
Managing plugins
wp plugin activate plugin-name
wp plugin deactivate plugin-name
wp plugin deactivate --all
wp plugin install plugin-name --activate
The ability to deactivate every plugin with one command is genuinely useful during troubleshooting — see disabling plugins when you cannot log in for when this matters most, since it works even if wp-admin itself will not load.
Managing users
wp user list
wp user create newusername user@example.com --role=administrator
wp user update 1 --user_pass=new-password
The last example resets a user's password directly by their user ID — useful when you are locked out of the dashboard entirely but still have SSH access, as an alternative to editing the database through phpMyAdmin.
Search and replace across the database
wp search-replace 'oldsite.com' 'newsite.com'
WP-CLI's search-replace command is specifically written to handle WordPress's serialized data correctly, which makes it one of the safest ways to do this job — safer than a manual find-and-replace in phpMyAdmin, which can corrupt serialized values if it is not aware of their structure. See searching and replacing inside a database for the background on why this matters. Add --dry-run first to see what would change without actually making the change, which is worth doing before running it for real.
Database export and import
wp db export backup.sql
wp db import backup.sql
Clearing cache and transients
wp cache flush
wp transient delete --all
Maintenance mode and cron
wp maintenance-mode activate
wp maintenance-mode deactivate
wp cron event list
wp cron event run --all
Putting a site into maintenance mode from the command line is useful immediately before a bulk operation like a database import, since it needs no plugin and takes effect the moment the command runs. The cron commands are equally useful for checking whether WordPress's own scheduled tasks are actually running as expected, which is otherwise invisible from the dashboard.
Running WP-CLI on a multisite installation
Most commands accept a --url= flag to target a specific site within a network, for example wp plugin activate plugin-name --url=subsite.example.com. Without it, WP-CLI generally acts on the main site of the network by default.
Why this is worth learning even if you rarely use it
The dashboard is fine for occasional changes. WP-CLI earns its place in two specific situations: when you need to repeat the same action across many plugins or users at once, and when the dashboard itself is unreachable — a plugin has broken the admin area, or the site is in a login loop — and SSH is the only way in. In both cases, a single command replaces what would otherwise be a slow manual workaround, or is not possible through the dashboard at all.
A command like search-replace or a bulk plugin update runs against the live site immediately, with no undo. The same backup discipline that applies to any other change to WordPress applies here — arguably more so, since a single command can affect the entire database at once.
Related reading
What SSH access on a shared hosting account actually lets you do, and how to turn it on and connect.
How to disable plugins when you cannot log inRename the plugin folder over FTP, or edit the database directly, when a broken plugin has locked you out of the dashboard itself.
How to search and replace inside a databaseA plain find-and-replace can silently corrupt serialized data — here is how to do it without breaking the site.
How to update WordPress without breaking your siteBack up, update one thing at a time, and check the site immediately — the order that keeps an update from becoming an outage.