Support article
WP-CLI: How to Manage WordPress from the Command Line
Learn to use WP-CLI to update WordPress and manage plugins, users, the database, cache, and tasks from SSH.
What WP-CLI is
WP-CLI is WordPress’s command-line interface. It lets you run administrative tasks from a terminal without opening a browser: checking and updating WordPress, installing or deactivating plugins and themes, creating users, exporting and importing databases, running safe search-and-replace operations, and managing cache, cron, and options.
It’s especially useful for managing several sites or recovering an install whose panel isn’t responding.
Requirements
You need SSH access, permission to run PHP from the console, WP-CLI installed by your provider or in your account, and access to the WordPress folder. The console’s PHP version can differ from the one the site uses — always check with wp --info.
Checking if WP-CLI is installed
Connect via SSH and run:
wp --info
wp cli version
If the command doesn’t exist, check whether your host offers WP-CLI or whether you can install it in your own user space by downloading the official PHAR file (wp-cli.phar) and running it with php wp-cli.phar. On shared hosting sudo may not exist, so don’t try to modify global paths without permission.
Running WP-CLI in the right folder
Go into the folder that contains wp-config.php:
cd /path/to/wordpress
wp core is-installed
wp option get home
If you run the command from another folder, use wp --path=/path/to/wordpress core version.
Basic diagnostic commands
wp core version
wp option get home
wp option get siteurl
wp plugin list
wp theme list
wp user list
wp cron event list
wp core verify-checksums
verify-checksums compares the core files against the official checksums, but it doesn’t check plugins, themes, or uploaded files.
Updating WordPress
Before updating, back up the files and database (see WordPress backup and restore) and check compatibility.
wp core check-update
wp core update
wp core update-db
wp core version
wp core verify-checksums
Managing plugins and themes
wp plugin install plugin-name --activate
wp plugin activate plugin-name
wp plugin deactivate plugin-name
wp plugin deactivate --all
wp plugin update --all --dry-run
wp plugin update --all
wp plugin delete plugin-name
Deleting files doesn’t always run the plugin’s uninstall routine. For themes: wp theme list, wp theme install theme-name, wp theme activate theme-name, and wp theme update --all. Keep at least one default theme available for diagnostics.
Managing users
wp user create newadmin email@yourdomain.com \
--role=administrator \
--user_pass='LongUniquePassword'
wp user update username --user_pass='NewLongPassword'
wp user set-role username editor
wp user delete username --reassign=OTHER_USER_ID
Avoid typing sensitive passwords in commands if the terminal history could be accessible to others.
Exporting and importing the database
wp db export wordpress-backup.sql
wp db import wordpress-backup.sql
wp db check
wp db optimize
Keep backups outside the public folder and restrict their permissions — an SQL file can contain users, emails, and password hashes.
Changing a URL with search and replace
WP-CLI correctly handles WordPress’s serialized data (see also how to change the WordPress URL). First simulate the change:
wp search-replace \
'https://old-domain.com' \
'https://new-domain.com' \
--all-tables-with-prefix \
--dry-run
If the report looks right, repeat without --dry-run. Back up before running it, and don’t add --all-tables without understanding it could modify tables that don’t belong to WordPress.
Managing options, cache, and WP-Cron
wp option get blogname
wp option update blogname 'New title'
wp cache flush
wp rewrite flush
wp cron event list
wp cron event run --due-now
Don’t change unfamiliar options — many contain serialized arrays or critical configuration. Flushing WP-CLI’s cache doesn’t always clear the server, plugin, or CDN page cache.
Working with a broken site
If a plugin or theme is causing an error when WordPress loads:
wp plugin list --skip-plugins --skip-themes
wp plugin deactivate plugin-name --skip-plugins --skip-themes
See how to deactivate WordPress plugins without admin access for more methods. Keep in mind MU-plugins can keep loading even when you use --skip-plugins.
Running as the correct user
On your own server, don’t run WP-CLI as root against a site whose files belong to a different user, unless you understand the consequences — you can create files with the wrong owner and cause update or security failures.
Automating tasks
#!/bin/bash
set -euo pipefail
cd /path/to/wordpress
wp db export "/safe/path/backup-$(date +%F-%H%M).sql"
wp core check-update
wp plugin update --all
wp theme update --all
wp core update
wp core update-db
Before automating, test each command separately, log the output, handle errors and notifications, and avoid unattended automatic updates on critical sites without testing first.
Useful global flags
wp --path=/path/wordpress plugin list
wp --url=https://network-site.com option get home
wp --skip-plugins --skip-themes core version
Common issues
”This does not seem to be a WordPress installation”
You’re not in the correct folder, or wp-config.php is missing. Use --path.
Incompatible console PHP
Check php -v and wp --info, and select the right PHP binary if the server has several versions.
Permissions error
Run as the site’s owning user and check ownership and permissions. Don’t fix it with 777.
WP-CLI loads a broken plugin
Add --skip-plugins --skip-themes and deactivate the responsible component.
Frequently asked questions
Is WP-CLI available on every hosting plan?
No. It depends on the service and SSH access. Check your plan’s features.
Is it safer than logging in to WordPress?
Not automatically. SSH needs to be secured and the commands have a lot of reach. Use keys, limited users, and backups.
Does WP-CLI work with Multisite?
Yes. Many commands support --network or --url — check each command’s documentation (see enabling and configuring WordPress Multisite).
Conclusion
WP-CLI lets you manage WordPress quickly and reproducibly for maintenance or recovery tasks. Start with read-only commands, use --dry-run when it’s available, back up before modifying the database, and always run as the correct user.