WP-CLI: Managing WordPress from the Command Line
What Is WP-CLI?
WP-CLI — the WordPress Command Line Interface — is the official tool for managing a WordPress installation straight from the terminal, without opening wp-admin. Nearly everything you can click in the dashboard has a one-line equivalent here.
Worth flagging up front: WP-CLI is for people comfortable in a terminal. It's usually unavailable on basic shared hosting — its home is VPS and dedicated servers, or plans that include SSH access.
💡 A simple analogy:
The WordPress dashboard is like driving a car: visual, one task at a time. WP-CLI is like scripting a robotic garage — a one-line instruction turns a job that would take 50 clicks into a command finished in seconds.
How WP-CLI Works
WP-CLI is a PHP file executed from the command line, not through a browser. That means it uses the server's PHP version, not whatever your web phpinfo() shows. The flow:
- You log into the server via SSH and change into the WordPress directory.
- WP-CLI reads
wp-config.php, connects to the database, and recognizes the installation context. - Commands execute directly — database queries, file operations, WordPress functions — with no HTTP layer in between.
Command structure is consistent: wp <action>, such as wp plugin list or wp user create.
Commands You'll Actually Use
wp core update # update WordPress
wp plugin update --all # update every plugin
wp cache flush # clear the object cache
wp db export backup.sql # dump the database to a file
wp user list # list all users
wp search-replace 'old.com' 'new.com' # fix URLs after migration
wp cron event run --due-now # run overdue cron events now
wp search-replace deserves its own spotlight. When moving domains or hosts, rewriting database URLs via raw SQL is a classic source of breakage. WP-CLI does it while respecting WordPress's serialized data structure — far safer than sed.
Why VPS Users and Agencies Care
For anyone managing many sites, WP-CLI's value is automation. Update commands can be scheduled through a cron job, so 20 sites on one server update uniformly without a single browser click. That's the standard pattern on an unmanaged VPS, where security and updates are entirely your responsibility.
Three other patterns you'll see in practice:
- Server migration. Dump the database, move the files, then
wp search-replaceandwp rewrite flush— the hosting move becomes one command sequence. - Debugging without login. Lost admin password?
wp user updatefixes it without an email reset. - Measured backups. A daily cron
wp db exportcomplements your provider's hosting backups.
One caution: WP-CLI runs as the same server user as the web. A destructive command aimed at the wrong target — a misplaced wp plugin delete — executes with no confirmation dialog.
Common Mistakes
Running commands in the wrong folder. WP-CLI is directory-based. wp core update outside a WordPress install gives a "not a site" error — or worse, updates the wrong install.
Forgetting file ownership. On a VPS you may log in as root while the web runs as www-data. After heavy WP-CLI operations, ownership often needs fixing so the site can still write.
Assuming WP-CLI exists everywhere. Budget shared hosting frequently has no SSH at all. Check your plan's specs first.
Updating without a backup. wp core update can still fail mid-way, just like a manual update. Export the database first — it's cheap and fast.
FAQs
Is WP-CLI safe to use?
Yes, as long as you understand the command you're running. The risk isn't WP-CLI itself — it's the command line's tendency not to ask questions. Start with read-only commands like wp plugin list before touching write operations.
Does WP-CLI replace the wp-admin dashboard?
No, and it wasn't designed to. Visual configuration, theme editing with previews, and one-off tasks stay more comfortable in the dashboard. WP-CLI wins for repeatable, bulk, and schedulable operations.
How do I install WP-CLI on a VPS?
Download wp-cli.phar, make it executable, move it onto the server's PATH (typically /usr/local/bin/wp), then run wp --info to verify. The official docs provide a one-line installer for Linux and macOS.
Disclaimer: Hosting Wiki articles are prepared for educational and reference purposes. Hosting technology keeps evolving, so some technical details may change over time.