WP-CLI Commands for VPS Owners: Install, Update, Repair
Install WP-CLI from the official phar, run it as the site's file owner, and use the WP-CLI commands a VPS owner needs most: updates, checksums, database export, search-replace.
WP-CLI is the official command-line tool for WordPress. It does over SSH what the dashboard does in a browser: update core and plugins, reset a password, export the database, replace a URL in every table. It also works when the dashboard does not load at all, which is when you need it most.
Ubuntu and Debian do not package it. You install one file, the phar (a PHP archive), from the official source, and then run every command as the user that owns the site's files, not as root. The WP-CLI commands below are the ones a VPS owner uses week to week.
Every subcommand and flag was checked against the official WP-CLI handbook and command reference; the commands were not run on a test server for this article.
Install WP-CLI from the official phar
These are the steps from the WP-CLI installation guide. WP-CLI needs PHP 7.2.24 or later, which any server that runs a current WordPress has. The steps are the same on Ubuntu, Debian, AlmaLinux and Rocky Linux.
cd /tmp
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
If --info prints the PHP and WP-CLI versions, the download works. To confirm the file is the one the project published, verify its GPG signature:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.asc
curl -L https://raw.githubusercontent.com/wp-cli/builds/gh-pages/wp-cli.pgp | gpg --import
gpg --verify wp-cli.phar.asc wp-cli.phar
The output must contain Good signature. Then make the file executable and move it into the path under the name wp:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
Update WP-CLI itself later with sudo wp cli update.
Run it as the file owner, not as root
WP-CLI loads WordPress, and with it the code of every plugin and theme. Run as root, that code has full control of the server, so WP-CLI stops with an error when root starts it and continues only with --allow-root. Do not use that flag on a server. There is a second, practical reason: files created by root (a new plugin folder, a cache file) can no longer be written by PHP, and dashboard updates start to fail.
Run commands as the owner of the WordPress files. On Ubuntu and Debian that is usually www-data:
# who owns the files?
stat -c '%U' /var/www/example.com/wp-config.php
# Ubuntu, Debian
sudo -u www-data wp --path=/var/www/example.com core version
# AlmaLinux, Rocky Linux (owner is usually apache or nginx)
sudo -u apache wp --path=/var/www/example.com core version
--path tells WP-CLI where WordPress is installed. You can leave it out when you are inside the WordPress folder. The examples below assume you ran cd /var/www/example.com first, and they write wp for sudo -u www-data wp to stay readable. If ownership on your site is mixed up, fix it first with WordPress file permissions.
Updates
wp core version
wp core check-update
wp plugin list --update=available
wp core update
wp core update-db
wp plugin update --all
wp theme update --all
wp core update-db runs the database upgrade that the dashboard would otherwise ask for after a core update. Check the result with wp core version and wp plugin list, then load the site in a browser. Take a database export first, as shown below.
Check files against the official checksums
wp core verify-checksums
wp plugin verify-checksums --all
The first command compares every core file with the checksums WordPress.org publishes for your version and reports files that were changed, plus files in wp-admin and wp-includes that do not belong there. The second does the same for plugins hosted on WordPress.org; plugins from other sources cannot be checked this way. A modified core file is a strong sign of a compromise. Cleaning up a hacked WordPress site describes what to do next.
Reset a user password
wp user list --role=administrator
wp user update admin --user_pass='a-new-long-password'
Use the login name, email address or ID from the list in place of admin. This works without access to the mailbox, unlike the "Lost your password?" link. The password ends up in your shell history; remove that line afterwards with history -d, or change the password again in the dashboard once you are logged in.
Export and import the database
wp db export - | gzip > ~/example-$(date +%F).sql.gz
gzip -t ~/example-*.sql.gz && ls -lh ~/example-*.sql.gz
With - as the file name the dump goes to standard output, so the file is written by your own shell into your home folder and not into the web root, where anyone could download it. wp db export takes the database name and credentials from wp-config.php.
gunzip ~/example-2026-11-22.sql.gz
wp db import ~/example-2026-11-22.sql
wp db check
An import overwrites the tables contained in the dump. The file must be readable by the user WP-CLI runs as. A dump on the same server is not a backup; see WordPress backups on a VPS.
Search and replace with a dry run
wp search-replace is the correct way to change a domain or switch stored URLs from http:// to https://. A plain SQL REPLACE breaks PHP serialized data, a format in which the length of each string is stored next to it. WP-CLI rewrites that data correctly.
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid --dry-run
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid
--dry-run runs the whole operation and prints a report of how many replacements each table would get, without saving anything. Read it, then run the command again without the flag. By default only the tables registered with WordPress are touched; --all-tables-with-prefix includes plugin tables that share the prefix but are not registered. Export the database before the real run, and flush the cache after it.
Cache, cron and maintenance mode
wp cache flush
wp cron event list
wp cron event run --due-now
wp cron event run wp_version_check
wp cache flush empties the object cache, for example Redis. It does not clear a page cache in nginx or in a caching plugin. wp cron event list shows every scheduled task with its next run time, --due-now runs all tasks that are due, and a hook name runs that one task immediately. A list full of overdue events means WordPress cron is not being triggered; see WordPress cron jobs.
wp maintenance-mode activate
wp maintenance-mode status
wp maintenance-mode deactivate
While active, visitors get the "briefly unavailable for scheduled maintenance" page. Use it around a database import or a large update, and always confirm with status that you switched it off again.
Read and change wp-config.php
wp config get DB_NAME
wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw
wp config get WP_DEBUG
--raw writes the value as it is, so true becomes the boolean and not the string 'true'. wp config set adds the constant if it does not exist yet. Set WP_DEBUG back to false when you have finished.
When the site is broken
A plugin or theme with a fatal error breaks WP-CLI too, because WP-CLI loads them. Two global flags skip that code:
wp --skip-plugins --skip-themes plugin list
wp --skip-plugins --skip-themes plugin deactivate broken-plugin
wp --skip-plugins --skip-themes theme activate twentytwentyfive
With both flags WordPress core loads alone, which is enough to deactivate the plugin that caused the error or to switch to a default theme that is installed. If you do not know which plugin it is, wp --skip-plugins plugin deactivate --all turns all of them off, and you reactivate them one at a time. The log-based way to find the culprit is in the critical error and white screen guide.
Task and command at a glance
| Task | Command |
|---|---|
| Update everything | wp core update, wp plugin update --all, wp theme update --all |
| Detect changed core files | wp core verify-checksums |
| Detect changed plugin files | wp plugin verify-checksums --all |
| Reset a password | wp user update LOGIN --user_pass=... |
| Dump the database | wp db export |
| Change the site URL in content | wp search-replace OLD NEW --dry-run |
| Empty the object cache | wp cache flush |
| Run due scheduled tasks | wp cron event run --due-now |
| Show a config constant | wp config get NAME |
| Work around a broken plugin | wp --skip-plugins --skip-themes ... |
The full list of commands and flags is in the official WP-CLI command reference.