How To Update A WordPress Via SSH

Manzeel Uprety
2 min readMay 1, 2020

--

WordPress should be updated as soon as a new version is available. An update brings improvement, features, stability improvements, and security fixes. Keeping your WordPress installation, plugins, and themes up to date is very important. If you are not updating your WordPress you are likely to be hacked through the security loopholes in the previous versions.

For most WordPress users updating to the latest version is straight forward: Log in to the WordPress dashboard, click on Update, and then select the option to update WordPress. Within a minute you will run on the latest version. Depending on the settings of your server, the automatic update option might not work. In this case, you’ll need to perform the updates manually via the FTP or SSH.

In this tutorial, you will learn how you can update WordPress via SSH.

Prerequisites

  • Domain name (example.com)
  • SSH Access with Root Permissions

Step 1:

Login to your server as a root user using SSH.

ssh root@123.112.75.80

Replace the IP address with your server’s actual IP address.

Step 2:

It is always advised to create a backup of your current WordPress site database; in case something went wrong. You can create one using the following command.

mysqldump -u USER -p DBNAME > /root/database_dump.sql

Replace the USER with your MySQL username and DBNAME with the name of your database. On executing the command, you will be asked to enter your database password.

Now, backup the site using the command below:

rsync -Waq /path/to/your/site /path/to/backup

Replace the path with your actual path while doing a backup.

Step 3:

You are now ready to start the update. A backup is in place if something goes wrong. Change the current working directory to the root directory and download WordPress.zip from the WordPress website.

cd /var/www/htmlwget https://wordpress.org/latest.zip

After downloading the zip file, unzip it using the following command.

unzip latest.zip

It will create a new WordPress directory.

Step 4:

Now you need to remove the wp-admin & wp-includes directory of your previous WordPress installation.

rm -rf oldwp/wp-includes
rm -rf oldwp/wp-admin

Let’s set the old directory name as oldwp.

Step 5:

Now move all the contents of the new WordPress directory to the old WordPress directory and replace all the files.

mv wordpress/* oldwp/

You will need to overwrite certain files and some directories. Press Y and move ahead.

Step 6:

Now delete the zip file and the empty WordPress directory.

rm -rf wordpress
rm -f latest.zip

Step 7:

Now, you need to run the upgrade script by going to

 http://example.com/wp-admin/upgrade.php

This command will complete the upgrade process and also update the database.

===============================

If you find this story helpful, feel free to buy me a virtual coffee 😉👇🏻

https://ko-fi.com/mnzel1

--

--

Manzeel Uprety
Manzeel Uprety

Responses (1)