How to upgrade a WordPress website via SSH

wordpress-logo-notext-rgbKeeping your WordPress installation, plugins and themes up to date is very important. You have to continually update WordPress immediately after a new version is released. The new versions will bring you new features, bug fixes, stability improvements and the most important – security fixes. If you do not update your WordPress  website it is very likely that your website will be hacked at some point. In this case you can lose your website content, your customers, lose your Google ranking, your website can be defaced, your server can be used for spamming, and many more. So, updating WordPress should be on the top of your list when it comes to the security of your Linux virtual server.

In this blog post we will explain how to update your WordPress installation to the latest available version through the Linux command line.

Log in to your server via SSH as user root and first of all make sure to create a backup of your website and database.

ssh root@IP

Create a backup of your MySQL database.

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

Replace DBUSER with your actual MySQL user and DBNAME with the name of the WordPress database. Once you execute the command you will be prompted to enter the password of the database

Now, backup the website files using the following command

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

Don’t forget to replace the paths in the command with the actual paths.

Now, once we have created a backup of the website files and the database, we can start the update. If something goes wrong, you can easily restore your WordPress website from the backup.

Change the current working directory to the document root directory and download WordPress zip archive from their official website

cd /var/www/html
wget https://wordpress.org/latest.zip

Unpack the zip archive

unzip latest.zip

This will create new ‘wordpress’ directory

Remove the ‘wp-admin’ and ‘wp-includes’ directories from your old WordPress installation

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
rm -rf oldwordpress/wp-includes
rm -rf oldwordpress/wp-admin

Replace ‘oldwordpress’ with the actual name of your WordPress directory.

Now, move all content of the newly created ‘wordpress’ directory to the old WordPress directory and overwrite all files and directories.

mv wordpress/* oldwordpress/

Delete the zip archive and the empty ‘wordpress’ directory

rm -rf wordpress
rm -f latest.zip

With this step the WordPress upgrade process from the command line is completed. Now you need to access http://yourdomain.com/wp-admin/upgrade.php to run the upgrade script and upgrade the database.

WordPress can be also upgraded through the command line interface using the WP-CLI interface. It is already explained in one of our previous blog posts.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to update your WordPress installation, plugins or themes for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

4 thoughts on “How to upgrade a WordPress website via SSH”

  1. Worked like a bomb, thanks. I did it this way because my server is not set up for ftp and when you try and do it while logged into your site it wants to do the upgrade via ftp

    Reply

Leave a Comment