This post shows students and new users steps to upgrade WordPress via SSH terminal console. When you’re running a WordPress website, one task that you’ll have to quickly learn is upgrading or updating WordPress content.
If you’re lucky, you may have a WordPress website that automatically updates when new versions are released. If that’s the case, then you should be all set. Nothing to do, but sit and relax.
However, not all WordPress websites are configured to automatically upgrade when new versions are released. If your WordPress site is configured where it can not self-update, then you may have to update from the server console or use other means.
An easy way to update WordPress content is from the server terminal. One can get to the server console via SSH or directly. Once on the terminal console, you should then be able to upgrade WordPress with ease.
When you’re ready to update or upgrade WordPress via SSH terminal, continue below:
How to backup WordPress database
Before making changes to your WordPress site, it is recommended that you always backup your database content. If you’re running MySQL or MariaDB database server, the commands below is how to backup a database.
sudo mysqldump -u root -p wp_database > wp_database.sql
Replace wp_database with your WordPress database that you want to backup. If you have plugin that can backup WordPress content, then use it to backup WordPress before continuing below.
How to backup WordPress content
You may also want to backup WordPress content. Assuming WordPress is installed in the /var/www/wordpress, use rsync to copy WordPress content directory to a backup location.
To do that, run the commands below.
sudo rsync -Waq /var/www/wordpress /path/to/backup/directory/
After backing up WordPress database and content, continue below to begin upgrading WordPress.
Delete WordPress wp-includes and wp-admin folders
To begin upgrading, delete the existing wp-admin and wp-include directories.
sudo rm -rf /var/www/wordpress/wp-includes sudo rm -rf /var/www/wordpress/wp-admin
After deleting WordPress existing folders for wp-admin and wp-includes folders, go and download WordPress updated content.
How to Download WordPress content
To download the latest WordPress content, simply run the commands below. Once the content is downloaded, the next command extracts it.
cd /tmp/ && wget https://wordpress.org/latest.zip
Unzip the download content using the commands below.
Replace WordPress content with latest
Finally, run the commands below to copy WordPress latest content to the root directory. Doing this will replace the wp-includes and wp-admin folders and overwrite any other folders with newer versions.
sudo mv /tmp/wordpress/* /var/www/wordpress
After copying the files, open your browser and browse to the WordPress URL for the site to initiate the upgrade.
Replace www.example.com in the URL with your own domain.
After a brief moment, your WordPress site should be updated with the latest files. You can then login to see the changes.
This post showed you how to upgrade WordPress. If you find any error above or have something to add, please use the comment form below.