Managing WordPress with WP-CLI on a VPS

Step 5: Search and replace (the migration command)

Moving a site to a new domain, switching from HTTP to HTTPS, or cleaning up leftover staging URLs all require search-replace across the entire database. Doing this through a plugin or the admin GUI on a large site will time out. WP-CLI handles it at the database level with no PHP memory constraints:

# Dry run first — shows what would change without touching anything
wp search-replace 'http://oldsite.com' 'https://newsite.com' \
    --dry-run --path=/var/www/mysite.com/public_html

# The real thing — skip the dry-run flag
wp search-replace 'http://oldsite.com' 'https://newsite.com' \
    --path=/var/www/mysite.com/public_html

A critical detail: this command handles serialized data correctly. A naive MySQL UPDATE ... REPLACE will corrupt serialized arrays and objects by changing string lengths without updating the serialization metadata. WP-CLI's search-replace deserializes, replaces, and re-serializes — safe for post content, widget data, theme options, and anything else WordPress stores in serialized format.

For HTTPS migrations specifically, add the --skip-columns=guid flag — the GUID field is a permanent identifier, not a URL, and shouldn't change even when the domain does:

wp search-replace 'http://oldsite.com' 'https://newsite.com' \
    --skip-columns=guid --path=/var/www/mysite.com/public_html

Step 6: Cron management

If you've disabled WordPress's built-in cron (DISABLE_WP_CRON), you're running scheduled tasks through a system cron job that hits wp-cron.php. WP-CLI gives you visibility into what's scheduled and the ability to run specific tasks on demand:

# See all scheduled cron events
wp cron event list --path=/var/www/mysite.com/public_html

# Run a specific event immediately
wp cron event run wp_privacy_delete_old_export_files --path=/var/www/mysite.com/public_html

# Run all due events
wp cron event run --due-now --path=/var/www/mysite.com/public_html

The system cron approach is covered in detail in the WordPress on Nginx guide — the short version is that a 10-minute curl to wp-cron.php replaces the default per-page-load cron, and wp-cli gives you manual control when you need it.


Step 7: Core, plugin, and theme updates

Updating everything from the CLI takes seconds and can be scripted across multiple sites:

# Update WordPress core
wp core update --path=/var/www/mysite.com/public_html

# Update the database after a core version bump
wp core update-db --path=/var/www/mysite.com/public_html

# Update all plugins and themes
wp plugin update --all --path=/var/www/mysite.com/public_html
wp theme update --all --path=/var/www/mysite.com/public_html

# Check what needs updating without doing anything
wp core check-update --path=/var/www/mysite.com/public_html
wp plugin list --update=available --path=/var/www/mysite.com/public_html
wp theme list --update=available --path=/var/www/mysite.com/public_html

For multisite setups or servers with multiple WordPress installs, a single script can loop through every site directory and update everything:

for site in /var/www/*/public_html; do
    echo "=== $site ==="
    wp core update --path="$site"
    wp plugin update --all --path="$site"
    wp theme update --all --path="$site"
done

Step 8: User management

Resetting a lost password, creating an admin account for a developer, or removing a compromised user — all faster from the CLI than the admin:

# Create a new administrator
wp user create devname dev@example.com --role=administrator --path=/var/www/mysite.com/public_html

# Reset a password
wp user update username --user_pass=new-password-here --path=/var/www/mysite.com/public_html

# List all users
wp user list --path=/var/www/mysite.com/public_html

# Delete a user and reassign their content
wp user delete olduser --reassign=otheruser --path=/var/www/mysite.com/public_html

Step 9: Maintenance mode and scaffolding

Before running bulk operations, put the site in maintenance mode so visitors see a friendly message instead of a broken page during updates:

# Enable maintenance mode
wp maintenance-mode activate --path=/var/www/mysite.com/public_html

# Run your updates...

# Disable maintenance mode
wp maintenance-mode deactivate --path=/var/www/mysite.com/public_html

For developers, wp scaffold generates boilerplate for plugins, child themes, and post types — but that's beyond the scope of day-to-day VPS management.


Quick reference

Install core
wp core download --path=…
Create config
wp config create --dbname=… --dbuser=… --dbpass=…
Install WP
wp core install --url=… --title=… --admin_user=…
Install + activate plugin
wp plugin install name --activate
Update everything
wp plugin update --all && wp theme update --all && wp core update
Optimize DB
wp db optimize
Search-replace
wp search-replace 'old' 'new' --dry-run (remove --dry-run when ready)
List cron events
wp cron event list
Reset password
wp user update username --user_pass=…
Maintenance mode
wp maintenance-mode activate / deactivate
Technical Audit Summary

All commands in this guide were tested against WordPress 7.0 using the latest upstream WP-CLI release. WP-CLI is a single PHP archive with no external dependencies — it works on any PHP 7.4+ environment, which is the floor for both WordPress 7.0 and all supported Debian/Ubuntu releases.

Last Audit: May 2026
Environment: Debian Trixie (13)
WordPress: 7.0
PHP-FPM: 8.5.6

2026-05-21: Initial publication. Covers wp-cli installation, core/plugin/theme management, database optimization, search-replace, cron visibility, user administration, and maintenance mode — the subset of wp-cli commands most relevant to VPS-based WordPress management.