Migrate EC2 WordPress Site to Lightsail

This guide will show you how to migrate a WordPress site that has been installed on an EC2 instance using the Bitnami for WordPress stack to a fresh Bitnami for WordPress Amazon Lightsail instance.

When I first launched this site I had just started using AWS cloud and decided to use an EC2 server because of the free tier option. While this was great during the first 12 months (free tier elegible), now that the free tier is no longer an option, I decided to migrate to an Amazon Lightsail instance to save money. At the time of writing, the cost for a 512MB Lightsail instance is $3.50 per month, whereas I’ve been paying more than $7.50 per month for a t2.nano instance in EC2.

I regularly use the [Bitnami for WordPress](1) stack for hosting dozens of WordPress sites. They are extremely easy to setup and once you get the hang of where things are installed compared to a self-install scenerio, they are even easier to use — the very handy control script at /opt/bitnami/ctlscript.sh is your friend. Because everything is stored within the /opt/bitnami directory, backing it all up at once and restoring somewhere else is very easy.

The process is simple and only takes a few minutes.

Step 1 - Backup the existing site

Click here to read my full post with detailed instructions for creating a backup and copying to S3.

SSH into your server

ssh -i /path/to/key.pem bitnami@{ec2_server_ip_address}

Create a full application backup

sudo /opt/bitnami/ctlscript.sh stop
sudo tar -pczvf /home/bitnami/backup/wordpress/full-application-backup-$(date +"%F").tgz /opt/bitnami
sudo /opt/bitnami/ctlscript.sh start

Copy backup file to safe storage location (I’m using an S3 bucket)

aws s3 cp /home/bitnami/backup/wordpress/full-application-backup-$(date +"%F").tgz s3://www.allcomone.com.s3

Step 2 - Launch a new Lightsail instance

  1. Login into your AWS Console and launch the Lightsail control panel
  2. Launch a new Bitnami for WordPress instance
  3. Create and assign a Static IP address for your new instance

Step 3 - Restore WordPress site from the backup in Step 1

SSH into your new instance

ssh -i /path/to/key.pem bitnami@{lightsail_static_ip_address}

Install and configure AWS-CLI

sudo apt update && sudo apt-upgrade -y
sudo apt install awscli
aws configure

paste in your ACCESS_KEY
past in your SECRET_KEY
enter desired default region (mine is us-west-2 for West-Oregon)
type json for output

Copy the backup file we created in Step 1 to current directory (/home/bitnami)

aws s3 cp s3://bucket-name/full-application-backup-$(date +"%F").tgz .

Note: The above command should be adjusted for your use case if all of the above steps do not happen on the same day.

Step 4 - Unpack WordPress backup and relaunch site

These instructions are based on [Bitnami’s documentation, which can be found here](2).

Stop all services

sudo /opt/bitnami/ctlscript.sh stop

Move the current stack out of the way

sudo mv /opt/bitnami /tmp/bitnami-backup

Uncompress the backup to the original directory

sudo tar -pxzvf /home/bitnami/full-application-backup*.tgz -C /

Start all servers

sudo /opt/bitnami/ctlscript.sh start

And that’s it! …well almost, you will still need to update your DNS settings to point your site to the new IP address of your Lightsail instance, but that is outside the scope of this document.

Author: Josh
Since I was a small boy – learning to write code while my friends played basketball – computers and technology have been and are my passion. My strong analytical skills, thorough knowledge and understanding of network protocols and technologies, and ability to learn new skills on the fly – enable me to troubleshoot, isolate, and resolve problems quickly and effectively.
how can we help you?

Contact us at the AllcomOne office nearest to you or submit a business inquiry online.

Looking for a top notch IT consultant?