Welcome to HowToShipIt — practical how-to guides for developers: code, AI tools, and servers, explained step by step.

WP-CLI: The Complete Guide to Managing WordPress from the Terminal (2026)

You can run an entire WordPress site without ever opening wp-admin. WP-CLI is the official command-line interface for WordPress, and it turns every dashboard click — installing a plugin, updating core, creating a user, moving a domain — into a command you can type, script, and repeat. If you manage one site, it saves you clicks. If you manage ten, it changes how you work entirely. This guide covers the install, the commands you will actually use every week, the search-replace workflow that pays for the whole tool, and the mistakes that break sites.

All commands verified against the official WP-CLI docs and handbook, November 2026. Current stable release: WP-CLI 2.12.0.

What WP-CLI is (and what it is not)

WP-CLI is the official command-line tool for WordPress, maintained by the WordPress community and shipping continuously since 2011. It does not replace WordPress — it talks to the same installation your dashboard does, through the same code, just without the browser. Anything you can do in wp-admin, you can do from the terminal: install and update plugins, import content, create users, run search-replace across a database, rotate keys, manage multisite networks.

Three things make it worth learning. First, speed: a plugin update that takes a dozen clicks becomes one line. Second, repeatability: a command that works once works the same way in a script, a cron job, or a deploy step. Third, reach: WP-CLI works when wp-admin does not — a broken plugin can lock you out of the dashboard while the terminal still works fine.

What it is not: a plugin. You do not install it from the WordPress dashboard, and you cannot install it on hosting that gives you no shell access. You need SSH access to the server (or a local copy of the site) and a Unix-like environment — Linux, macOS, FreeBSD, or Cygwin. Windows support is limited; WSL is the practical route there.

Install WP-CLI in about a minute

The current stable release is WP-CLI 2.12.0, published on 7 May 2025. It needs PHP 7.2.24 or later and WordPress 4.9 or later. In practice, run it on a supported PHP 8.x release — the minimums are floors, not recommendations. The wp db commands also call the MySQL or MariaDB client programs, so those need to be installed where WP-CLI runs.

The standard install downloads the Phar archive, checks it runs, makes it executable, and moves it into your PATH:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Then confirm it works:

wp --info

That prints the WP-CLI version, PHP version, and environment details. If you want to verify the download before trusting it, the project publishes a signature file alongside the Phar:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.asc
gpg --verify wp-cli.phar.asc wp-cli.phar

There are other install paths — Homebrew (brew install wp-cli), Composer, and a wp.bat wrapper on Windows — but the Phar method is the one the official handbook documents first, and it works identically on any server. Many managed hosts preinstall WP-CLI; check with wp --info before installing your own copy. To update later, run wp cli update (add --stable for production, --nightly only if you know why you want it).

Your first five WP-CLI commands

WP-CLI finds WordPress by looking in your current working directory, so the first habit to build is changing into the site directory before running anything that changes the site. Get that wrong and a command either fails or — worse — runs against the wrong site.

cd /var/www/yoursite
wp --info
wp core version
wp plugin list
wp theme list

Those four read-only commands tell you the version of everything and confirm WP-CLI can see the installation. Two more flags solve the “wrong site” problem permanently. --path points WP-CLI at a specific installation, and --url picks the site on a multisite network:

wp --path=/var/www/yoursite core version
wp --url=example.com plugin list

The second habit: run WP-CLI as the site’s system user, not root. Commands run as root create files owned by root, and your web server then cannot write to them. Use sudo -u www-data wp ... (or whatever user owns the site files) on a server. And if a command ever asks for a password, prefer --prompt over typing it into the command line, where it lands in your shell history — the official docs show this pattern for wp core install.

Manage WordPress core from the terminal

The wp core family covers the whole lifecycle: download, configure, install, update, and verify. Installing WordPress from scratch is three commands and takes seconds:

wp core download
wp core config --dbname=mydb --dbuser=myuser --dbpass='strong-password' --dbhost=localhost --dbprefix=wp_
wp core install --url=example.com --title="My Site" --admin_user=admin --admin_password='strong-password' --admin_email=you@example.com --skip-email

Note that wp core install creates the database tables and the admin user — the famous five-minute install, done in seconds. The --skip-email flag stops it emailing the new admin credentials. If you omit --admin_password, WP-CLI generates a random one for you.

For an existing site, the update workflow is:

wp core check-update
wp core update
wp core update-db

wp core update replaces the files; wp core update-db runs any database migrations the new version needs. Run both — skipping the second is a common cause of “database update required” screens. And if you ever suspect core files have been tampered with, wp core verify-checksums compares every file against the official release.

Plugins and themes without the dashboard

Plugin and theme management is where WP-CLI earns its keep on a weekly basis. The pattern is the same for both:

wp plugin list --update=available
wp plugin install query-monitor --activate
wp plugin update --all --dry-run
wp plugin update --all --exclude=akismet
wp theme update --all --dry-run

Always dry-run updates first. wp plugin update --all --dry-run shows exactly what would change without changing anything — the proposed change set, while the site stays untouched. The --exclude flag keeps a plugin you are deliberately holding back out of a bulk update. And wp plugin list --fields=name,status,version,update gives you a compact status table you can pipe into a script or a log.

Installing from a zip or URL works the same way — wp plugin install https://example.com/my-plugin.zip --activate — and deactivation is one word: wp plugin deactivate plugin-name. When a plugin update goes wrong, wp plugin deactivate --all followed by reactivating them one at a time is the fastest way to find the culprit, and it works from the terminal even when the dashboard is a white screen.

Users, posts, and media

WP-CLI handles the content side of WordPress too. Creating a user with a specific role, resetting a lost admin password, or listing every administrator takes seconds:

wp user create editor-name editor@example.com --role=editor
wp user list --role=administrator
wp user reset-password admin

Bulk content work is where the terminal pulls ahead of the dashboard. Need a hundred draft posts for testing, or a list of every published post of a custom type?

wp post list --post_type=post --post_status=publish --format=count
wp post create --post_title="Hello World" --post_status=draft --post_content="Draft body."
wp media import image.jpg --post_id=123 --title="Hero image"
wp media regenerate --yes

wp media regenerate --yes rebuilds thumbnail sizes after a theme change — the kind of job that is either a slow plugin in the dashboard or one line here. The --format flag is worth learning early: most list commands accept --format=table, --format=csv, --format=json, or --format=count, which makes WP-CLI output directly usable by other tools.

The database: export, import, and search

Before any risky operation, export a backup. WP-CLI makes it a one-liner you can put in a script:

wp db export ~/backups/$(date +%Y%m%d).sql
wp db import ~/backups/2026-11-17.sql
wp db search "old-domain.com"
wp db optimize

wp db export dumps the whole database to a SQL file; wp db import restores it. wp db search greps the database for a string without touching it — useful before a search-replace, and a fast way to find where a stray URL or shortcode lives. Remember that these commands shell out to the mysql client, so the database credentials come from wp-config.php and the client binary must be present.

wp search-replace: the command that pays for WP-CLI

Moving a site between domains, or from HTTP to HTTPS, means replacing a URL everywhere it appears in the database — posts, options, widgets, serialized settings. Doing that with raw SQL corrupts serialized data, because serialized strings store their own length. wp search-replace handles serialized data intelligently, recalculating lengths as it goes, and never changes primary key values.

The rule is simple: dry-run first, always.

wp search-replace 'http://old.com' 'https://new.com' --all-tables --dry-run
wp search-replace 'http://old.com' 'https://new.com' --all-tables

The dry run reports how many replacements it would make, table by table. Only when the count looks right do you run it for real. Three flags cover the edge cases you will hit in practice:

wp search-replace 'http://old.com' 'https://new.com' --all-tables --skip-columns=guid
wp search-replace 'oldurl.com' 'newurl.com' --precise
wp search-replace foo bar --export=database.sql

--skip-columns=guid leaves the GUID column alone — WordPress treats GUIDs as permanent identifiers, not display URLs, and the official docs use this in their own examples. --precise forces PHP processing for every column instead of fast SQL queries; slower, but more reliable on complex serialized structures. --export writes the transformed data to a SQL file without touching the live database, so you can inspect the result or apply it elsewhere. Tables without a primary key are skipped automatically.

Cron, cache, and maintenance mode

WP-Cron only runs when somebody loads a page, which is why scheduled posts and plugin jobs slip on low-traffic sites. WP-CLI gives you visibility into what is scheduled and lets you run it on a real clock. (The full story — why WP-Cron is not a real cron and how to replace it — is in our guide to disabling WP-Cron and setting up real cron.)

wp cron event list
wp cron event run --due-now
wp cron test

wp cron event list shows every scheduled hook and when it is due; wp cron event run --due-now runs everything that is due right now; wp cron test checks whether the loopback request WP-Cron depends on actually works. The production setup pairs a disabled WP-Cron with a system cron entry:

wp config set DISABLE_WP_CRON true --raw
*/5 * * * * cd /var/www/yoursite && wp cron event run --due-now --quiet

Maintenance mode is built into WP-CLI since WordPress 6.6 — no plugin needed:

wp maintenance-mode activate
# ...do your work...
wp maintenance-mode deactivate

And the three cache commands you will reach for after deployments and content imports:

wp cache flush
wp transient delete --all
wp rewrite flush

wp rewrite flush regenerates the rewrite rules after registering a custom post type or changing a permalink structure — the fix for 404s on new content types.

Rescue a broken site with WP-CLI

This is the section that justifies installing WP-CLI before you need it. A bad plugin can white-screen the dashboard, but the terminal does not load the dashboard — and WP-CLI can skip loading plugins and themes entirely:

wp --skip-plugins --skip-themes plugin list
wp plugin deactivate --all
wp option get siteurl
wp option update siteurl https://example.com

That sequence diagnoses the site without loading the broken code, disables everything so the site loads again, and fixes the two options that most often break after a domain move. From there, reactivate plugins one at a time until the breakage returns — you have found your culprit. Pair this with the debugging workflow in our WordPress debug.log guide: enable the log, reproduce the error, read the exact file and line, fix it with WP-CLI.

Two more rescue tools worth knowing: wp core verify-checksums for tampered core files, and wp db check / wp db repair for a database that reports corruption. Neither needs the dashboard, and both run in seconds.

Automate it: aliases, SSH, and nightly scripts

WP-CLI’s real power is that commands compose. Define aliases in wp-cli.yml and you can run a command against staging or production by name:

wp @prod search-replace 'https://staging.example.com' 'https://example.com' --all-tables --dry-run
wp @prod maintenance-mode activate

Or run against a remote server over SSH without logging in first:

wp --ssh=user@example.com:/var/www/yoursite plugin list

A nightly maintenance script ties it together — backup, update check, cache clear, cron run — and a single cron entry runs it at 3 a.m.:

#!/bin/bash
# /usr/local/bin/wp-maintenance.sh
SITE=/var/www/yoursite
BACKUP=~/backups/$(date +%Y%m%d).sql
cd "$SITE"
wp db export "$BACKUP"
wp plugin update --all --dry-run
wp cron event run --due-now --quiet
wp cache flush
0 3 * * * /usr/local/bin/wp-maintenance.sh

Keep the update step as a dry run in the script until you trust the workflow — a scripted update that breaks a plugin at 3 a.m. is worse than no script at all. Log the output, check it in the morning, and only then let the script apply updates. WP-CLI is also designed to be extended: wp scaffold plugin my-plugin generates a plugin skeleton, wp eval '...' runs one-off PHP against the loaded WordPress install, and wp package install adds community commands. The project is even positioning WP-CLI as the command-driven layer AI agents use to manage WordPress — the same stable commands, driven by something other than your keyboard.

7 WP-CLI mistakes that break sites

1. Running as root. Files created as root cannot be written by the web server. Always run as the site owner: sudo -u www-data wp ....

2. Search-replace without a dry run or a backup. A typo in the replacement string rewrites the whole database. Export first, dry-run second, run third.

3. Running in the wrong directory. WP-CLI operates on the WordPress installation in your current directory. Use --path in scripts so the command cannot drift.

4. Copying commands from old tutorials. wp core status, wp site status, and wp site info do not exist in WP-CLI 2.12 — they return “not a registered subcommand”. Verify commands against the current reference, not a 2019 blog post.

5. Updating everything blindly. wp plugin update --all with no dry run, no backup, and no --exclude for the plugin you are holding back is how a Tuesday morning becomes a restore exercise.

6. Editing wp-config.php by hand for values WP-CLI manages. Use wp config set DISABLE_WP_CRON true --raw instead of hand-editing the file — it validates the constant and keeps the formatting consistent.

7. Forgetting the database client. wp db export fails if the mysql binary is not installed, even though WordPress itself runs fine. Install the client on any machine where you run wp db commands.

WP-CLI cheat sheet

Command What it does
wp --info Show WP-CLI, PHP, and environment details
wp core version Show the installed WordPress version
wp core update && wp core update-db Update core files, then run database migrations
wp plugin list --update=available List plugins with updates waiting
wp plugin update --all --dry-run Preview plugin updates without applying them
wp user create name email --role=editor Create a user with a given role
wp db export backup.sql Dump the database to a SQL file
wp search-replace old new --all-tables --dry-run Preview a database-wide find and replace
wp cron event run --due-now Run every cron event that is due
wp maintenance-mode activate Put the site into maintenance mode
wp cache flush Flush the object cache
wp --skip-plugins --skip-themes plugin list Diagnose a broken site without loading plugins

Install WP-CLI today, even if you only use it for updates and backups this week. The commands are small and the payoff compounds: every dashboard chore you move to the terminal becomes something you can script, schedule, and repeat across every site you manage. The next time a plugin white-screens your dashboard, you will already have the tool that fixes it.

Further Reading & References

Leave a Comment