How to Update WordPress via SSH Terminal
Updating WordPress using the SSH terminal lets you manage your website’s core files, themes, and plugins directly from your server using text commands.
WP-CLI is a command-line tool for WordPress. Think of it like typing instructions into your computer instead of clicking buttons on a screen.
This method is useful when automatic updates don’t work or if you need to pick an exact version, like WordPress 6.5.
You can update WordPress core with a simple command like `wp core update`, giving you direct control over your site’s files.
Update WordPress using SSH by executing WP-CLI commands. Back up your database and content first. Then, use `wp core update` to update WordPress core and `wp plugin update –all` for plugins.
How to backup WordPress database
Backing up your WordPress database before updating via SSH is a smart first step. This creates a copy of all your site’s important information, like posts and comments, so you can restore it if anything goes wrong during the update process. Use the command: sudo mysqldump -u root -p wp_database > wp_database.sql.
sudo mysqldump -u root -p wp_database > wp_database.sql
Replace wp_database with the actual name of the WordPress database you want to back up. If you have a plugin that can back up WordPress content, use that before proceeding.
How to backup WordPress content
Run the commands below to perform this backup.
sudo rsync -Waq /var/www/wordpress /path/to/backup/directory/
Delete WordPress wp-includes and wp-admin folders.
Next, 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
Once the existing wp-admin and wp-includes folders are deleted, the next step is to download the updated WordPress content.
How to Download WordPress content
To download the latest WordPress content, run the commands below. After downloading, use the following command to extract the files.
cd /tmp/ && wget https://wordpress.org/latest.zip
Finally, unzip the archive.
unzip latest.zip
Replace WordPress content with the latest
After backing up your WordPress site, replace your old files with the latest version using an SSH terminal command. This command moves the new files to the correct place on your server, making sure your site is up-to-date. Run this command to update your site's files: sudo mv /tmp/wordpress/* /var/www/wordpress.
sudo mv /tmp/wordpress/* /var/www/wordpress
After copying the files, open your browser and navigate to your WordPress site's URL to initiate the upgrade.
http://www.example.com/wp-admin/upgrade.php
Replace www.example.com in the URL with your domain name.
After a brief moment, your WordPress site should be updated with the latest files. You can then log in to see the changes.
That's it!
Conclusion:
This post showed you how to upgrade WordPress. Please use the comment form below if you find any errors or have something to add.
No comments yet — be the first to share your thoughts!