Guides · Server software · updated 3 Dec 2026
How to update WordPress safely with WP-CLI (core, plugins and database)
Most WordPress compromises come from outdated plugins, so updates matter, but an update done blind can take a site down. With WP-CLI you can back up, update in a controlled order and check the result in a few minutes.
Run WP-CLI as the site's user, from the site folder
Never as root: files created by root can break uploads and updates.
cd /path/to/site sudo -u SITEUSER wp core version sudo -u SITEUSER wp plugin list --update=availableBack up the database and the files
Keep the backup outside the web root.
sudo -u SITEUSER wp db export ~/backup-$(date +%F).sql tar czf ~/site-files-$(date +%F).tgz --exclude=wp-content/cache .Put the site in maintenance mode
Visitors see a short notice instead of a half-updated site.
sudo -u SITEUSER wp maintenance-mode activateUpdate plugins and themes first, then core
Plugins first, so an incompatibility shows up before core changes.
sudo -u SITEUSER wp plugin update --all sudo -u SITEUSER wp theme update --all sudo -u SITEUSER wp core update sudo -u SITEUSER wp core update-dbVerify and reopen
Checksums confirm core files match the official release; flush caches and test the main pages.
sudo -u SITEUSER wp core verify-checksums sudo -u SITEUSER wp cache flush sudo -u SITEUSER wp maintenance-mode deactivate
Common mistakes
- Updating on a Friday evening with no backup.
- Abandoned plugins: if a plugin has no updates for years, replace it rather than keep patching around it.
- PHP version: a new WordPress release can drop support for the PHP version you run.
How to undo it
Restore the database with wp db import ~/backup-DATE.sql and the files from the archive, or roll one plugin back with wp plugin install NAME --version=X.Y.Z --force.
Sources
Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.