How to Upgrade WordPress on Linux

WordPress is a popular blogging platform and content management system.  This brief article explains how to upgrade WordPress on the Linux command line.  A message on your Dashboard says that a new release is available ?  Proceed as follows.

The system I am using is running Debian 8, but the procedure should work on any Linux distro, including any Raspberry Pi.

Download WordPress

Let’s take the latest release at the time of writing (June 2016), version 4.5.3.  The system to be upgraded is currently running WordPress 4.5.2, which has been installed as /usr/share/wordpress.  First, logout of the WordPress Dashboard if you are logged in.

Then get the software:

$ cd /usr/share
$ sudo wget https://wordpress.org/latest.zip
2016-06-25 20:30:54 (1.95 MB/s) - ‘latest.zip’ saved [8424250/8424250]

Backup the Old Software

Move the old WordPress installation:

$ cd /usr/share
$ sudo mv wordpress wordpress.bak

Install the Latest Version

Unzip the new software:

$ sudo unzip -q latest.zip

Create a link from the new installation to your existing configuration file /etc/wordpress/wp-config.php.

 $ cd wordpress
 $ sudo ln -s /etc/wordpress/wp-config.php wp-config.php

Check that the link is valid by reading the first few lines of the configuration file:

$ head wp-config.php

Copy Data

Next, copy the data from the old installation to the new installation. This will put your blog data under the new installation, while keeping a copy under the previous version as a backup. Note the dot at the end of the second command:

$ sudo mv wp-content wp-content.empty
$ sudo cp -rp ../wordpress.bak/wp-content .

Upgrade database

Log into your WordPress Dashboard. If a database upgrade is required, a message will appear. Click the Upgrade button if requested. The database will be updated. Not every WordPress upgrade will trigger a database upgrade.

A message at the top left of your WordPress Dashboard confirms the new version:

WordPress 4.5.3 running some theme.

That completes the upgrade procedure.

A Note About WordPress Database Versions

The database upgrade is only required if the WordPress database release is different in the new version of WordPress. It can be checked as follows:

$ cd /usr/share
$ grep "wp.*version ="  wordpress*/wp-includes/version.php 
wordpress.bak/wp-includes/version.php:$wp_version = '4.5.2';
wordpress.bak/wp-includes/version.php:$wp_db_version = 36686;
wordpress/wp-includes/version.php:$wp_version = '4.5.3';
wordpress/wp-includes/version.php:$wp_db_version = 36686;

In this case, it can be seen that the old version of WordPress (now under WordPress.bak) was version 4.5.2 and the new version (under wordpress) is version 4.5.3, as expected. Also the database version in both cases is 36686. As the number was 36686 in both cases, no database upgrade was triggered this time.

One thought on “How to Upgrade WordPress on Linux

  1. Pingback: Install WordPress Blog on Raspberry Pi | Unix etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.