How to upgrade a WordPress website via SSH

Keeping 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 VPS/Server.

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

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.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Directory and File Structure - Linux

Directory/Folder StructureFrom amongst the several directories found within your cPanel account,...

PHP require, require_once errors

If you an error that looks like one of these... Warning:...

PHP Parse error: syntax error, unexpected $end

This error is typically caused by a missing } used in PHP to denote content belonging to a WHILE,...

How to drop tables from a database in phpMyAdmin?

This article will demonstrate how to drop (permanently delete) tables from a database in...

How to drop tables from a database in phpMyAdmin?

This article will demonstrate how to drop (permanently delete) tables from a database in...

Powered by WHMCompleteSolution