Upgrading Ubuntu LTS, PHP and WordPress

These are the things that I did to upgrade my AWS EC2 server. Not exactly the instance but the software that is running on it. I am jotting this down since I might have a use for it some time later. Perhaps somebody in a similar situation as I am will find it useful too.

Commands will be prefixed with a :~$ to be more readable and obvious. But do not include it when typing the same commands in your terminal. e.g. :~$ sudo ls -la should just be sudo ls -la when you copy/type it in.

So without further ado…

Backup, Backup, Backup

This is the first thing that I did. You should too. In fact, you can create a snapshot, make a volume from it, then spin another EC2 instance where you can sort of practice if the upgrade will come out successfully or not. This means you have to shell out $$$. Not that expensive but if you can afford it then why not.

What I did for backup:

  • Created a Snapshot of my EC2 Volume on the AWS Console
    • AWS > Login > EC2 > Elastic Block Store > Snapshots
  • Tar-balled my /home data and downloaded these to my desktop.
    • :~$ sudo tar -cjvf backup-of-home.tar.bz2 /path/to/home/folder
  • Dumped the entirety of my databases. Copied to my desktop.
    • :-$ mysqldump -u [user name] -p [database name] > [dump file]
    • Do this for all your databases or you can use the – –all-databases – option instead of specifying the DB name.
    • A meaningful [dump file] could be: allmy-databases-20200517.sql
    • The easier way could be if you have phpMyAdmin installed on your server. Then you can go that route.

Update from Ubuntu 14.04 LTS to Ubuntu 16.04 LTS

The 3 commands to upgrade from one LTS to the next:

  1. Updated my operating system: :~$ sudo apt-get update
    • This command fetches a list from the remote repositories of packages that has newer versions or patches.
  2. Proceeded to upgrade: :~$ sudo apt-get upgrade
    • Updating in #1 is not doing the actual update. This is obvious enough but may be confusing especially for newbies. The upgrade command does the actual replacing of applications that needs to be.
  3. Finally, :~$ sudo do-release-upgrade
    • What happens is that it will commence moving your OS version from the current to the next LTS (Long Term Support) up the ladder. It will only move one step up, not to the latest LTS release. So in my case from version 14.04 the next one would be 16.04, while the latest LTS is already at 20.04.
  4. Notes to consider:
    • If you have third-party software repositories in your list, try to disable them during this LTS upgrade. Mine is so vanilla because everything I need for web hosting is already offered by Ubuntu’s finely curated application repositories. And for servers, I usually stick to stable or LTS releases.
    • During the upgrade it asked me on what to do with the configuration files. The choice is to keep current or replace it with package maintainer’s version, and some other options. I always went with the default choice for all. Default is to keep current.
    • After the upgrade I did a – :~$ lsb_release -a – just to see if the LTS version really changed.
  5. Last but not least, reboot server.
    • At the end it will ask you to restart or not. You can hold off on this and do other things. I went with No answer. But it is good to restart at least once after the upgrade.
    • Once ready, reboot your instance from the AWS console.
      • AWS > Login > EC2 > Instances > Select appropriate instance > Right Click or Actions > Go to Instance State > Reboot

One of the main reasons why I upgraded to Ubuntu 16.04 Xenial Xerus is to get the newer versions of MySQL and PHP. I did not want any hacks, such as adding third-party sources, just to get MySQL 5.7 and PHP 7.0 (at the very least). These are the minimum that I wanted (for now) to get the higher versions of WordPress (v 5.4.x) working.

Replacing PHP 5.x with PHP 7.x

At this point I needed to make sure that PHP is enabled and running. The upgrade should have restarted MySQL and Apache2 services by default. I am pretty sure it did. Checked the status of each and found it running normally. But there was something wrong with the PHP module that prevented my sites from loading properly.

The upgrade should also have pulled in PHP7.0. But it won’t be enabled. It would still have been PHP 5.6 running. At this point I am not sure why PHP failed to load. It could be that I just needed to re-enable it with – :-$ sudo a2enmod php5. However, my objective was to jump to PHP7.x. Seeing that the a2enmod command did not list the php7.0 module, I knew I needed to install another package. Below are the commands to do it.

:-$ sudo apt install libapache2-mod-php7.0

:-$ sudo a2enmod php7.0

Restarted the Apache2 service as required – :-$ sudo service apache2 restart – or use the systemd way, which I find longer to type.

While at this point, I also installed other modules such as php7.0-mysql, php7.0-xml, etc. Below is the command that I used to help me look for the appropriate packages.

:-$ sudo apt-cache search php | grep php7

In fact before doing the upgrade, it is best to note what PHP modules are there. This is easily done with – :-$ php -m – but something that I did not do, causing one of the active plugins to not work at all. I later found out what was going on by looking at the logs.

Install the latest WordPress

At the time of this writing the most recent version is 5.4.1.

  • WordPress self-hosted site > Login > Dashboard > Updates
    • Updated plugins and themes afterwards. I think there was an update all button but I can’t remember.
    • WordPress will take care of everything including changes to the underlying back-end database schema. I just waited for a few minutes for the version upgrade to complete. There were zero errors.
  • Notes to consider:
    • I tested my current theme, plugins and custom modifications on an updated WordPress version locally. If you can’t do this, create a clone of your EC2 instance so you can test on it before doing the actual upgrade. Things might break. Best to be prepared.

Similar Posts:

Notice: This article was published on May 17, 2020 and the content above may be out of date.