WP-CLI: A Practical Guide to Managing WordPress from the Command Line
WP-CLI is the official command-line interface for managing WordPress. It handles many routine tasks without opening wp-admin and is useful for maintenance, migrations, automation, and troubleshooting.
WP-CLI is not available on every hosting platform. You need SSH access, a working WP-CLI installation, and permission to access the WordPress directory.
What WP-CLI is and when to use it
You can inspect WordPress core, manage plugins, themes and users, export the database, flush object cache, and perform controlled URL replacements. It does not replace backups, staging, or compatibility testing.
Before you begin
- Confirm that your hosting includes SSH and permits WP-CLI.
- Create a full file and database backup before updates or data changes.
- Use staging for changes that may affect a production website or store.
- Connect with a limited account rather than root.
- Confirm the correct document root.
1. Connect through SSH and verify WP-CLI
cd /path/to/wordpress
wp --info
wp core versionIf wp is not found, ask the provider whether WP-CLI is available. For “This does not seem to be a WordPress installation”, verify the directory or use --path=/correct/path.
2. WordPress core
wp core version
wp core check-update
wp core verify-checksumsChecksum verification can identify modified core files, but does not inspect plugins, themes, or uploads. Before wp core update, back up and test on staging.
3. Plugins and themes
wp plugin list
wp plugin list --update=available
wp plugin status plugin-slug
wp plugin activate plugin-slug
wp plugin deactivate plugin-slug
wp theme list
wp theme status theme-slugDo not mass-disable plugins on a live store without a maintenance plan. Test updates on staging and apply them one at a time.
wp plugin update plugin-slug
wp theme update theme-slug
4. Users
wp user list --fields=ID,user_login,user_email,roles
wp user get 1Review unknown administrators, but do not delete a user until identity and content ownership are confirmed. Never expose credentials in shell history.
5. Database
Warning: database commands can affect the entire site. Create a backup before any write or optimization operation.
wp db check
wp db export wordpress-before-change.sqlConfirm the export exists, has a plausible size, and is outside the public web directory. Large databases may require another process.
6. Cache
wp cache flushThis flushes the WordPress object cache. It does not necessarily clear page cache, CDN cache, or server cache.
7. Updates
wp core check-update
wp plugin list --update=available
wp theme list --update=availableThese are checks. Before wp core update, wp plugin update, or wp theme update, create a backup, test on staging, and prepare rollback.
8. Search and replace with a safe preview
WP-CLI handles serialized data, but an incorrect replacement may alter many records. Always run a dry run first:
wp search-replace 'https://old.example' 'https://new.example' --all-tables-with-prefix --dry-runReview the tables and replacement count. Only after verification and backup should you repeat without --dry-run. Multisite and custom tables need extra checks.
Common problems
- Command not found: WP-CLI is unavailable or outside PATH.
- Wrong path: use the document root or
--path. - Database connection error: inspect wp-config.php and database availability.
- Permission denied: verify ownership and permissions; do not use sudo casually.
- Fatal error: inspect logs and roll back the latest change.
- Timeout or memory error: split the task or contact the provider.
Basic security practices
- Use SSH keys where supported and never share credentials.
- Avoid destructive commands unless necessary.
- Keep exports and backups outside public directories.
- Verify the site, wp-admin, forms, and logs after changes.
- If you are unsure about a command's scope, stop and request support.