How to Use WP-CLI to Manage WordPress Faster from the Terminal
If you run WordPress on a VPS, the dashboard slows routine work down. Update screens, user forms, and settings pages take minutes for jobs that take seconds in a terminal. When you use WP-CLI to manage WordPress, one command installs a plugin, updates core, creates a user, or exports the database. This guide covers the commands you will use most, with the flags and safety steps that keep a live site intact.
WP-CLI is the official command-line tool for WordPress. It talks to the same database and files as your site, so a change made with WP-CLI shows up in the dashboard at once. Run it from the directory that holds WordPress, or point it there with --path. Back up before any write command.
Use WP-CLI to Manage WordPress Core, Plugins, and Users
Each dashboard job maps to one command. The pattern is wp, then the object, then the action: wp plugin update --all updates every plugin, wp user list lists users, wp option get siteurl reads one setting. Check a new command with wp help before you run it.
That pattern also makes repeat work easy. Updating ten sites by hand means ten dashboard logins. With WP-CLI, you run the same update command in each site directory.
Install WP-CLI and Run Your First Command
Install WP-CLI once per server. Download the Phar file, make it executable, and move it into a directory on your PATH:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
Run WP-CLI as the user that owns the WordPress files, usually www-data on a LEMP stack, with sudo -u www-data wp .... Run as root, and WP-CLI stops and asks for --allow-root. That flag works, but files created as root can end up with the wrong owner. Use the site owner account when you can. If you are setting up a server from scratch, start with a clean LEMP stack install for WordPress on a VPS so file ownership is right first.
Common WP-CLI Commands in One Table
The WordPress command line rewards short, exact commands. Type the object and action first, and add flags only when you need them.
| Job | Command | What it does |
|---|---|---|
| Update core | wp core update |
Installs the latest core release |
| Update database | wp core update-db |
Runs pending database upgrades |
| Install a plugin | wp plugin install wordpress-seo --activate |
Installs from WordPress.org and turns it on |
| Update all plugins | wp plugin update --all |
Updates every installed plugin |
| List users | wp user list |
Shows users, roles, and emails |
| Create a user | wp user create editor1 [email protected] --role=editor |
Creates a user with the editor role |
| Export the database | wp db export backup.sql |
Writes a full database dump to a file |
| Search and replace a URL | wp search-replace 'http://old.example.com' 'https://new.example.com' --all-tables |
Replaces the old URL across tables |
| Run due cron events | wp cron event run --due-now |
Runs scheduled events that are due |
| Regenerate thumbnails | wp media regenerate --yes |
Rebuilds image sizes for media files |
Install, Update, and Check WordPress Core
For a new site, WP-CLI handles the whole install. Download core, create the config file, then install:
wp core download --path=/var/www/example.com
wp config create --dbname=example_db --dbuser=example_user --dbpass='your-password' --dbhost=localhost
wp core install --url=https://example.com --title="My Site" --admin_user=admin [email protected]
WP-CLI asks for the admin password during install if you leave it out. For an existing site, run wp core update, then wp core update-db if a database upgrade is pending. Check the result with wp core verify-checksums, which compares core files against the official release and flags any file that has changed.
Install, Activate, and Update Plugins and Themes
Install from WordPress.org by slug, activate in the same command, and update everything in one pass:
wp plugin install wordpress-seo --activate
wp plugin update --all
wp theme install twentytwentyfive --activate
wp theme update --all
Use wp plugin list before an update round so you know what will change, and run it again after to confirm the new versions. If an update breaks something, wp plugin deactivate plugin-slug turns it off without opening the dashboard, and wp plugin install plugin-slug --version=1.2.3 --force puts a known version back. Paid plugins are not in the WordPress.org directory, so install them from a zip file: wp plugin install /path/to/plugin.zip --activate.
Manage Users, Options, and Media from the Terminal
User admin is straightforward with wp-cli commands. Create an account, list accounts by role, and reset a password without a reset email:
wp user create editor1 [email protected] --role=editor
wp user list --role=administrator
wp user reset-password editor1
Options are the settings stored in the wp_options table. Read one with wp option get siteurl and change one with wp option update blogname "My Site". After you change image sizes in a theme, old uploads keep their old thumbnails until you rebuild them. wp media regenerate --only-missing --yes rebuilds only the sizes that do not exist yet, which is the faster choice on a large media library.
Back Up and Move a Database with WP-CLI
A wp-cli database backup is one command, and it belongs before any job that rewrites data:
wp db export backup-2026-11-23.sql
wp db check
wp db import backup-2026-11-23.sql
wp db export writes the whole database to a file in the current directory. Give the file a date in its name, and move it off the server or out of the web root when you are done. wp db import restores a dump, and it overwrites the current database, so confirm you are in the right site directory before you run it.
Search-replace is the command people reach for after a move. Always run it with --dry-run first, read how many replacements it would make, and only then run it for real:
wp search-replace 'http://old.example.com' 'https://new.example.com' --all-tables --dry-run
wp search-replace 'http://old.example.com' 'https://new.example.com' --all-tables
WP-CLI handles serialized data correctly, which is why it beats a raw SQL find-and-replace that can break plugin settings stored as serialized arrays. Use the full URL, including the protocol. If you are moving a whole site, read a full WordPress migration from shared hosting to a VPS first, because the file move, the database import, and the search-replace have to happen in the right order.
Run Cron and Clean Up the Database
WordPress cron only fires when someone visits the site, which is a weak trigger on a low-traffic VPS. A system cron job that calls wp cron event run --due-now runs due events on a real schedule instead of waiting for a visitor. List what is registered first with wp cron event list. For the full setup, follow the guide to run WordPress cron properly on a VPS instead of fake visits.
Cleanup suits the terminal too. Expired transients, old revisions, and trashed posts pile up in the database, and WP-CLI can clear each group without a plugin:
wp transient delete --expired
wp post delete $(wp post list --post_type=revision --format=ids) --force
wp db optimize
Run the inner wp post list on its own first and check the count before you pipe it into a delete. For a fuller pass, see how to clean up WordPress revisions and transients that slow down your site. Finish with wp db optimize to reclaim space after a large delete, and wp cache flush if the site uses an object cache.
Test Changes Safely Before You Touch the Live Site
Test plugin updates, theme changes, and search-replace runs on a copy first. A copy has the same database and files, so a command that fails there would have failed on the live site too, and you find out without any downtime. Build the copy with wp db export and a file copy, import the database into the staging database, then run search-replace to swap the live URL for the staging URL. The full copy process is covered in the guide to clone a WordPress site for testing without touching the live one.
Mistakes That Break Sites
Running a command in the wrong directory is the first mistake: wp option get siteurl tells you which site you are about to change, so check it before any write command. Running search-replace without --dry-run is the second, and skipping the database export before it is the third. Together they turn a one-line URL fix into a restore job.
Running everything as root is the fourth. It works in the moment, then leaves files the web server cannot write to. The fifth mistake is trusting a command because it printed no error. wp plugin update --all can report success while a plugin still needs a database upgrade, so follow it with wp core update-db where relevant and load the site in a browser before you call the job done.
Start with one site and five commands: check the version, list plugins, list users, export the database, and run due cron events. Once those feel routine, add installs, updates, and search-replace to the set, always with a backup first.