How to Upgrade WordPress Core from the Command Line with WP-CLI
In this series of blog posts, we will cover the basic-but-useful tasks with WP-CLI, such as upgrading WordPress core and managing your plugins. By the end of it all, you should be comfortable using WP-CLI and discovering more ways you can use it to simplify your life!
WP-CLI is a great tool for simplifying WordPress administrative tasks. One of the most important WordPress administrative tasks is being able to manage the main code that makes up WordPress. WP-CLI makes this simple; if you read our first blog post on WP-CLI, you already know how to configure this tool and use it to control all your WordPress blogs.
This week, we’re going to find out how to achieve the best upgrade ever!
Get started by checking the version of WordPress you’re running:
[user@server]$ wp core version
Is there a newer version available? The WordPress community releases new versions many times a year, minor versions to fix bugs and vulnerabilities, and major versions when new features are added. Chances are, you need to upgrade the core WordPress files to enjoy performance enhancements, security fixes, and new features; this is done for you if you use a managed WordPress platform like DreamPress. The classic way—using the WordPress admin dashboard—requires you to start your browser and click around your site a dozen times. WP-CLI simplifies this task immensely:
[user@server]$ wp core update
This will check for a newer version of WordPress, and install it if there is one. If you need to downgrade WordPress for some reason (for instance, you realize too late that the upgrade breaks your theme), WP-CLI can do this as well. The following command will downgrade WordPress core to a version you specify:
[user@server]$ wp core update --version=VERSION_NUMBER --force
The “–force” flag is required, as it is not recommended that you downgrade WordPress. Downgrading WordPress could leave your site vulnerable to security issues (and we never want that).
Sometimes you do not wish to upgrade WordPress to a new major release (because you use a plugin or a theme that doesn’t support it yet), but wish to upgrade to a minor release—from version 4.3 to 4.3.3, for example. DreamHost and WordPress.org always recommend upgrading to the newest version, but if you do not wish to do so, you can use the following command:
[user@server]$ wp core update --minor
This is less likely to introduce problems into your website, but if you only upgrade to a new minor release you might not be getting all the possible fixes or new features. By default, WordPress is configured to upgrade itself to new minor releases.
If you have a staging and production site configured in WP-CLI, you can upgrade the staging site using:
wp @staging core update
Then, after you make sure all of your plugins still work and the upgrade went well, you can upgrade your production site as well:
wp @prod core update
And that’s it! In next week’s episode, we’ll show you how to easily manage WordPress plugins using WP-CLI. Stay tuned!
Looking for WordPress hosting? Check out the benefits of starting a WordPress website on DreamHost today!