WP-CLI is the official command-line tool for managing WordPress: updating plugins, running database operations, managing users, and inspecting site configuration, all without opening wp-admin in a browser. On a self-managed VPS, where you are already comfortable in a terminal for the rest of the server, it is faster than clicking through the WordPress admin for routine maintenance and it is scriptable, which matters once you want to automate updates or back up the database as part of a larger workflow.
This guide installs WP-CLI, confirms it can see your WordPress install, and covers the maintenance commands you will use most often. It assumes you already have WordPress running on the VPS, for example by following the [guide to deploying WordPress with Nginx and PHP-FPM](/guides/deploy-wordpress-nginx-php-fpm), and that you have a non-root sudo user.
WP-CLI ships as a single executable Phar file. Download the latest build directly from the WP-CLI project:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Confirm the download works before installing it system-wide:
php wp-cli.phar --info
Output:
OS: Linux 6.8.0-generic #1 SMP x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php8.3
PHP version: 8.3.14
php.ini used: /etc/php/8.3/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar
WP-CLI version: 2.11.0
Make the file executable and move it into your PATH so it runs as a plain wp command from anywhere:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
WP-CLI is now installed system-wide. The next step is confirming it can actually talk to your WordPress install rather than just running standalone.
WP-CLI needs to be run from inside a WordPress install's root directory, the one containing wp-config.php, since that is how it locates the site and its database credentials. Navigate to it and check the core version:
cd /var/www/example.com
wp core version
Output:
6.7.1
If this returns a version number, WP-CLI has successfully read wp-config.php and connected to the database. Run commands as the same user that owns the WordPress files, typically www-data, rather than root; running WP-CLI as root works but will change file ownership on anything it touches, which then breaks Nginx or PHP-FPM's ability to write to those files afterwards. Prefix commands with sudo -u www-data when logged in as your own sudo user:
sudo -u www-data wp core version
WP-CLI is now confirmed working against your actual WordPress install, running as the correct user. From here, the commands below cover the maintenance tasks you will reach for most often.
List installed plugins along with their update status in one command, which is faster than paging through the wp-admin plugins screen:
sudo -u www-data wp plugin list
Update every plugin that has a new version available:
sudo -u www-data wp plugin update --all
Back up the database before making changes you might need to undo. This exports a SQL dump to the current directory:
sudo -u www-data wp db export backup-$(date +%F).sql
Clear the object cache after making configuration changes that depend on fresh cached values, such as after editing wp-config.php constants:
sudo -u www-data wp cache flush
Search and replace across the database is one of the operations WP-CLI does meaningfully better than the admin UI, since it runs as a single serialized-data-aware database operation rather than a plugin trying to do the same thing through PHP. This is the standard way to update URLs after a domain change or migration:
sudo -u www-data wp search-replace 'http://old-domain.com' 'https://example.com'
Run this without --dry-run only once you have confirmed the old and new values are correct; add --dry-run first to preview what would change without writing anything, since a wrong search-replace touches every row in the database that matches.
Once you trust the commands above, wiring plugin updates into a cron job removes the need to log in and run them manually. Open the crontab for the www-data user:
sudo crontab -u www-data -e
Add a line that exports a database backup and updates plugins every night at 2am, logging the output so you can check it ran:
0 2 * * * cd /var/www/example.com && wp db export /var/backups/wordpress/backup-$(date +\%F).sql && wp plugin update --all >> /var/log/wp-cli-updates.log 2>&1
Automating plugin updates without a backup step ahead of them is how a bad update turns into a bad afternoon; keep the export in the same cron line so there is always a recent database dump to fall back on. For a fuller backup strategy that also covers site files, not just the database, see the [guide to backing up WordPress on a VPS with a cron job](/guides/backup-wordpress-vps-cron-job).
You can now manage plugins, run database operations, and handle routine WordPress maintenance entirely from the command line, and you have a cron job keeping plugins current with a backup taken first. From here, the same wp command works for managing users, exporting content, and inspecting site health, all documented in WP-CLI's own command reference if you want to go further than the maintenance basics covered here.
Move a live WordPress site from shared hosting to a VPS: database export with my...
How to set up SSH key authentication on Ubuntu and disable password logins to se...
How to configure UFW and Fail2Ban on Ubuntu to protect your VPS from port scans...