WordPress

WP-CLI: Managing WordPress From the Command Line

What WP-CLI is, how to install and use it safely, everyday commands for updates, databases, users and searches, and how teams fold it into maintenance and deployment.

Quick answer: WP-CLI is the official command-line interface for WordPress. It lets you install plugins, update core, manage users, run database searches, clear caches and script repeatable maintenance without clicking through wp-admin. Use it over SSH on staging and production with care: take backups first, prefer staging rehearsals for destructive commands and document the exact commands your team relies on.

Why command line helps WordPress teams

The admin UI is fine for editorial work. It is slow and click-prone for:

  • Updating many plugins across environments
  • Search-replace after domain changes
  • Creating users with known roles
  • Bulk post meta cleanup
  • Generating reports for maintenance

WP-CLI turns those into scripts you can review in pull requests and run the same way every time. That consistency is a gift during WordPress maintenance and launches.

Install and access (practical notes)

On many managed hosts, WP-CLI is preinstalled. On VPS setups you install the Phar following current project instructions and place it in your PATH. You need SSH access and filesystem permissions for the WordPress install.

Confirm you are in the right environment before running commands:

  • Check hostname and path
  • Run wp core version and wp option get siteurl
  • Prefer separate aliases for staging and production shells

If SSH is new to your team, pair WP-CLI training with clearer WordPress client training so editors still use wp-admin for content while technical staff use CLI for system tasks.

Everyday commands worth knowing

Core and updates

  • wp core check-update
  • wp plugin list / wp plugin update --all (after staging tests)
  • wp theme list
  • wp language core update

Never update production first. Rehearse on staging, especially on sites with custom code or heavy ecommerce.

Database

  • wp db export before risky changes
  • wp db import on staging copies
  • wp search-replace for domain migrations (with --dry-run first)

Domain changes and HTTPS moves are classic CLI jobs. Coordinate with your redirect plan and website deployment process.

Users and roles

  • wp user create
  • wp user update
  • wp user list

Useful when locking down leftover contractor accounts after a project.

Content and media

  • wp post list
  • wp post delete (careful)
  • wp media regenerate after image size changes

Cache and cron

  • Clear object/page caches when your stack integrates with WP-CLI packages
  • Trigger cron events when diagnosing schedules

Safety rules

  1. Backup first. Database and files. Prove restores on staging occasionally.
  2. Dry-run search-replace. Read the change count before applying.
  3. One production change at a time when diagnosing.
  4. Do not pipe random snippets from the internet without reading them.
  5. Watch multisite flags. Commands behave differently with --url and network options.
  6. Keep secrets out of shell history when passing passwords; prefer interactive or env-based patterns your host documents.

Hosting quality affects how pleasant CLI work is. Good WordPress hosting includes SSH, staging and snapshots.

WP-CLI in maintenance retainers

A simple monthly CLI-assisted checklist:

  • Export DB snapshot
  • List outdated plugins/themes
  • Apply updates on staging
  • Smoke test key templates and forms
  • Apply the same update set on production during a window
  • Record versions in the maintenance log

This is faster than screenshot tours through wp-admin and leaves an audit trail. Combine with monitoring so you notice failures between retainers; see WordPress monitoring.

Automation and deploys

Teams often call WP-CLI from deploy scripts:

  • wp cache flush
  • wp rewrite flush
  • wp transient delete --all when appropriate
  • Run database deltas you trust

Keep interactive prompts out of CI. Fail loudly when the command is not available. Document required WP-CLI version if you depend on newer packages.

For child theme and code workflows, CLI sits beside Git rather than replacing it. Theme structure still benefits from a proper child theme approach instead of editing parents on the server.

Troubleshooting with CLI

Helpful diagnostics:

  • wp plugin deactivate --all on a staging copy to isolate faults
  • wp theme activate to test with a default theme
  • wp option get / wp option update for broken URLs
  • wp eval only when you know what you are evaluating

When the admin is locked behind a fatal error, CLI may still work and let you deactivate the offender. That alone can justify learning it.

Teaching the wider team

Not everyone should have production SSH. A practical split:

  • Editors: wp-admin only
  • Developers/maintainers: SSH + WP-CLI
  • Agency leads: read-only logs and staging access

Put common command recipes in your website documentation so knowledge does not live in one person’s history file.

Useful packages and extensions

The core phar covers most needs. Community packages add convenience for specific hosts or workflows. Only install packages you trust, and pin versions when you automate. Treat a WP-CLI package like a plugin: it runs with significant power over your site.

Examples of tasks people script:

  • Generate a maintenance report (plugin versions, stale users, cron event counts)
  • Seed staging with anonymised data policies your legal team accepts
  • Bulk change author IDs after staff changes

Keep scripts in private repos with README steps, not as undocumented one-liners in chat.

Search-replace without tears

Migrations between domains or from HTTP to HTTPS are where WP-CLI earns its reputation. A careful sequence:

  1. Backup
  2. wp search-replace old new --dry-run
  3. Review counts for GUID and serialized data warnings
  4. Run for real with the flags recommended for your case
  5. Flush caches and re-save permalinks
  6. Spot-check posts with embedded URLs and shortcodes

Serialized data mistakes cause subtle bugs. Read the command help for your WP-CLI version every time; defaults evolve and your memory may be wrong.

Pairing CLI with plugin discipline

CLI makes it easy to install plugins quickly. That is not always a virtue. Keep an allowlist of approved plugins, prefer fewer better tools and remove what you install for experiments. Fast install plus slow removal is how sites accumulate risk. Essential stacks should stay intentional, closer to an essential plugins mindset than to impulse installs.

Example mini playbook: plugin update night

  1. Announce a short maintenance window if needed
  2. wp db export to a dated file off the web root
  3. On staging: update plugins, run smoke tests on home, contact, account, checkout
  4. On production: repeat the same plugin versions
  5. wp plugin list snapshot saved to the maintenance log
  6. Watch error logs for thirty minutes

That playbook is dull on purpose. Dull is how you avoid excitement at midnight. Store it with your other runbooks so freelancers follow the same steps.

FAQ

Is WP-CLI safe on production?

Yes when used carefully with backups and staging rehearsals. It is powerful, which means it can also delete data quickly.

Does WP-CLI replace phpMyAdmin?

For many tasks, yes, and with better repeatability. Some hosts still offer phpMyAdmin; prefer CLI when you can script the work.

Can WP-CLI manage multisite?

Yes, with network-aware parameters. Read the docs for your exact command before running it across sites.

What about managed hosts without SSH?

Some restrict CLI. Choose hosting that matches how you want to operate, or use the host’s approved tooling.

Click less, repeat more

WP-CLI makes WordPress maintenance measurable and repeatable. Learn a small set of commands, wrap them in checklists and keep production changes boring. If you want WordPress care that includes disciplined updates and documentation, see how we help businesses turn visitors into customers.

About the author

Imran M

Leave a Reply

Your email address will not be published. Required fields are marked *

Ready to improve your website?

Let's build a faster, higher performing website.