Ubuntu Server Migration: Moving my WordPress blog to a new DigitalOcean Droplet

Ubuntu Server Migration: Moving my WordPress blog to a new DigitalOcean Droplet

Back when I started this blog, rather than using generic WordPress hosting, I decided to get my own virtual server and do it all myself. My server was now out of date, and this is how I migrated form my old droplet to a new Ubuntu 20.04 droplet.

In this post I have documented the steps of backing up my existing environment, creating a new environment and migrating my WordPress blog to it. Checkout the video below where I go over the whole process:

My Host: DigitalOcean

The host I chose to use is use DigitalOcean I’ve been using them for some years and I’m very happy with the service and pricing. They have many options and allow you to scale to your requirements including hosting in many geographic locations.

Note: The link above is my Referral link, If you sign up using it we both win! Everyone I refer gets $100 in credit over 60 days. Once they’ve spent $25 with DigitalOcean, I’ll get $25.

DigitalOcean Terminology

For the sake of clarity in this article, in DigitalOcean terminology:

  • Droplet: A virtual machine, built from a starting image (many options exist). For people familiar with AWS, think of this as being like an EC2 instance.
  • Volume: A virtual storage location, highly customisable cloud storage. For people familiar with AWS, think of this as being like S3 storage.

DigitalOcean Migration Related Documentation

If you are migrating with DigitalOcean, then I recommend checking their documentation:

Migration Process

As always with a significant project, it’s worth having a plan, there is a lot that can go wrong (or be hard to fix) if you haven’t had the right plan and lined everything up that you need in advance. The worst case scenario is having a new environment which doesn’t work properly and an old one which is now unstable after the migration.

Preparation

Before we do anything with a new host, it’s good to check the existing one for anything we have forgotten and make backups. But first, we need to make sure that the network changes will happen smoothly.

Get configuration

It can be handy to get various configuration and informational values into a text file/view on screen. What you need to see the details of depends on your applications installed and configuration, but some general examples to start with are:

# System version
uname -r

uname -m
 
# Services & If they are running
service --status-all

# Firewall
ufw status

ufw status verbose

DNS Records & TTL

The Domain Name System (DNS) is how web addresses like roman-halliday.com are converted into IP addresses for connecting to servers. DNS records are like a phone book, and once looked up a record will be kept for the duration of the Time To Live (TTL).

A day or two before migration, set the TTL values in your DNS records for each impacted hostname to refresh each hour. At the start of the day for migration, drop it down to 1 minute:

   60 seconds =  1 min   : Day and Time of migration
 3600 seconds =  1 hour  : Day(s) before migration
86400 seconds = 24 hours : Good operational normal

Backup (using a volume)

Blessed are the paranoid for they test their backups

system administration proverb

The old server (droplet) needed to be backed up, although I could have copied files directly between the two. Keeping a copy of the key files for some time can be handy to fall back on (if I forgot something in the migration).

I decided to use a volume, which is basically some extra disk space that I can move between hosts (droplets). The basic steps are:

  1. Create a volume.
  2. Format the volume on the original host.
  3. Mount the volume on the original host.
  4. Copy all required data to the volume.
  5. Unmount the volume, so it can be mounted on the new host (droplet).

Documentation:

All-in-One WP Migration

It’s easiest if WordPress instances in the old and the new environment are the same. The easiest way to do this is to upgrade the old one to the latest version (then do the same on the new one once it’s set up).

This is a good time to install All-in-One WP Migration on the old WordPress instance. Then backup and save the exported file. It’s just easier with the DNS records pointing at the old host (they have to be changed in configuration of the new host).

Create The New Droplet

I opted to save some time by using a WordPress preconfigured droplet. This already had the Linux Apache and MySQL stack (LAMP) already installed and partially configured. It also had a WordPress installation ready and some scripts to streamline configuration.

Information & Documentation: WordPress by DigitalOcean

Connect To The New Droplet

Once everything is migrated, I can re-use the same PuTTY configuration (including keys). But first, I will just punch in the IP address and use a password to connect as the root user.

Initial Configuration

Note, I chose to make these changes before following the setup script. It’s personal preference which way round to do these things.

Install Updates

The first thing I do is install the latest updates on a host, this is for security and bug fixes.

This command updates the cache of application information, then installs the latest updates to all applications:

apt-get update && apt-get upgrade -y

Migrate DNS Records

Point to new droplet using the DNS controls (keeping the TTL low in case we want to change back.

Configure Apache & WordPress

Much of the configuration can be done following the setup script built into the DigitalOcean droplet. Most of this configuration is very helpful, although admittedly, some of the WordPress configuration will get overwritten.

Restore Backup (WordPress Migration)

It’s easiest if the new instance is the same version of WordPress as the old one, so if you updated the old one to the newest version, it’s a good idea to upgrade the new one too. You can go ahead without doing this, but you will get extra requests to update the database.

After updating, install All-in-One WP Migration on the new WordPress instance. Then restore the previously exported file.

I had to allow for larger files to be uploaded, I did this by changing the .htaccess file under the root of the WordPress installation to contain the below lines (I removed the file after the upload/update):

php_value upload_max_filesize 256M
php_value post_max_size 200M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300

Restore Files From Backup

To get files back which have been backed up (or to compare configuration files), mount the volume as before on the new host: https://www.digitalocean.com/docs/volumes/how-to/mount/

Restore DNS TTL Records

Once everything is as it should be, go to the networking panel and change the TTL records on the DNS configuration to something like 86400 seconds (24 hours).

Drop The Old Droplet

Once we are live with everything on the new droplet, the old one can be deleted/terminated. I chose to power mine down for a few days first. Just to be safe that I could fire it up and use it if I’d missed anything.

Other Steps & Docs

I’ve moved a collection of other notes to my wiki, they were too varied for a single blog post, and highly specific to my case. For reference, they can be found here:

Leave a Reply

Your email address will not be published.

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