How to Upgrade WordPress with WP-CLI

Upgrading WordPress is a crucial step in maintaining website security and optimal performance. Regular WordPress updates help fix bugs, improve features, and enhance security. However, upgrading WordPress can be time-consuming and tedious, especially for larger websites with multiple plugins and themes.

Fortunately, there is a better way to upgrade WordPress that is faster, more efficient, and less prone to errors than traditional web U.I. methods. wp-cli is a command-line interface tool for managing WordPress websites. It allows you to perform various tasks through the terminal or command prompt, including updating plugins, themes, and WordPress core.

In this article, you will learn how to upgrade WordPress using wp-cli. The article will guide you through connecting to your website, checking the current version of WordPress, updating WordPress core, plugins, and themes, and verifying the upgrade. Following these steps, you can keep your website secure and up-to-date with minimal effort.

Before You Begin

Before upgrading WordPress, it’s essential to back up your website to avoid losing any data or files. You can use a plugin like UpdraftPlus or manually back up your website by copying the website files and database to your local computer.

Alternative Linux Server Backup Method

For users that do not want to use or afford premium backup plugins, the following method can be useful to learn if you have access to the terminal environment on your server.

To create a backup of your website’s database, follow these steps:

  1. Open your terminal or command prompt and navigate to the root directory of your website.
  2. Enter the following command to create a backup of your website’s database:
mysqldump -u username -p database_name > database_name.sql

Replace “username” with your MySQL username and “database_name” with the name of your WordPress database. You will be prompted to enter your MySQL password.

  1. Save the generated SQL file to your local computer.

To archive your WordPress folder, follow these steps:

  1. Navigate to the root directory of your website using your terminal or command prompt.
  2. Enter the following command to create an archive of your WordPress folder:
tar -czvf website_backup.tar.gz *

This command will create a compressed archive of all files and folders in the root directory of your website.

  1. Save the generated archive file to your local computer.

Once you have created the backup of your website’s database and archived your WordPress folder, you can save them to a backup location such as an external hard drive or cloud storage.

Using these terminal commands, you can manually back up your WordPress website quickly and efficiently without needing phpMyAdmin or other third-party tools. If you need to restore the MySQL database, visit our guide, How to Backup and Restore a MySQL database which is the same process for MariaDB.

Step 1: Connect to Your Website

To connect to your website using wp-cli, open your terminal or command prompt and navigate to your website’s root directory. The root directory is the main folder that contains all the files and folders for your website.

To navigate your website’s root directory, open your terminal or command prompt and use the cd command. For example, if your website’s root directory is located at /var/www/html, you can use the following command:

cd /var/www/html

Once you’re in the root directory, you must ensure you have the latest version of wp-cli. To update wp-cli, enter the following command:

wp cli update

This command will download and install the latest version of wp-cli. Updating wp-cli is essential because it ensures you have the latest features and bug fixes.

Step 2: Check the Current Version of WordPress

Before upgrading WordPress, you need to know the current version of WordPress that you’re running on your website. This information will help you determine whether your website needs an update and which version to update.

To check the current version of WordPress that you’re running on your website using wp-cli, enter the following command:

wp core version

This command will display the current version of WordPress installed on your website. If you’re unsure whether the version displayed is the latest version of WordPress, you can check the official website to confirm.

Step 3: Update WordPress Core

Updating WordPress Core is essential in keeping your website secure and up-to-date. To update WordPress Core using wp-cli, enter the following command:

wp core update

This command will automatically update WordPress Core to the latest version. However, if you want to update to a specific version of WordPress, use the following command instead:

wp core update --version=X.X.X

Replace X.X.X. with the specific version of WordPress that you want to update. For example, if you want to update to version 5.8, enter the following command:

wp core update --version=6.2

Step 4: Update WordPress Plugins

WordPress plugins are essential for extending your website’s functionality and features. However, outdated plugins can also pose a security risk to your website. It’s essential to keep your plugins up-to-date to ensure your website is secure and running optimally.

To update all WordPress plugins to their latest versions using wp-cli, enter the following command:

wp plugin update --all

This command will update all installed plugins on your website to their latest versions. By updating all plugins simultaneously, you can save time and ensure that your website uses the latest versions.

Step 5: Update WordPress Themes

Updating WordPress themes is essential for maintaining your website’s appearance and performance. Themes are responsible for the overall look and feel of your website. Outdated themes can cause compatibility issues, security risks, and poor website performance.

To update all WordPress themes to their latest versions using wp-cli, enter the following command:

wp theme update --all

This command will update all installed themes on your website to their latest versions. By updating all themes simultaneously, you can save time and ensure that your website uses the latest versions of all themes.

Step 6: Verify the Upgrade

After completing the update process, verifying that the upgrade was successful is essential. To verify that the WordPress upgrade was successful using wp-cli, enter the following command:

wp core version

This command will display the new WordPress version installed on your website. If the version displayed matches the version you updated, then the upgrade succeeded.

By verifying the upgrade, you can ensure that your website runs on the latest WordPress version and that all the changes and improvements have been applied correctly.

Conclusion

In conclusion, upgrading WordPress using wp-cli is a quick and efficient way to ensure that your website runs on the latest WordPress version. It’s essential to keep your website up-to-date to prevent security breaches and improve its performance. Following the steps outlined in this guide, you can keep your WordPress website secure and up-to-date.

Remember to perform regular backups and updates to keep your website secure and running smoothly. Testing your website’s functionality after each update is also a good practice to ensure everything works correctly.

If you’re new to WordPress or command-line interfaces, it might take a while to get used to wp-cli. However, learning how to use it is worthwhile as it helps you keep your website secure and up-to-date. If you’re interested in installing wp-cli on a Linux or Unix-type server, check out our guide on How to Install WP-CLI in a Linux Server for WordPress.

Additional Resources and Relevant Links

Here are some additional resources and links related to upgrading WordPress with WP-CLI:

  • WP-CLI Official Documentation: The official documentation for WP-CLI is a great resource for learning more about the command-line interface and how to use it to upgrade WordPress. It includes a detailed guide on how to upgrade WordPress using WP-CLI, as well as many other helpful commands and features.
  • WordPress Codex: The WordPress Codex is the official documentation for WordPress. It provides a wealth of information on how to use WordPress, including how to upgrade it. While not specifically focused on WP-CLI, the Codex is still a valuable resource for anyone looking to learn more about upgrading WordPress.
  • WP-CLI on GitHub: The WP-CLI GitHub repository is where you can find the latest version of WP-CLI, as well as contribute to its development. It’s also a great place to report bugs and request new features.
  • WordPress Security Checklist: Upgrading WordPress is an important part of keeping your website secure. This checklist provides a comprehensive guide to securing your WordPress site, including how to upgrade WordPress using WP-CLI.