Migrate WordPress to EC2 (AWS)

I’ve totally geeked out and I’ve migrated my site to Amazon Web Services. Here’s how to migrate WordPress to EC2 instance on AWS.

My WordPress site had become intermittently slow and the console had become almost unusable so I decided it was time for a change.

I came across the AWS offer for the Free Usage Tier so that seemed like a good idea. I’d been interested in putting AWS through it’s paces but it’s been a long time since I’ve been hanging out with ssh so it required me to brush up on some of my Linux. I’m now back in the world of LAMP.

Hopefully you will notice a speed improvement with the site. Miraculously, at the same time I started migrating the site, my DNS host started to have performance issues. (Let me know if there is anything broken…)

I’m sure I’ll write some posts about what I learn on AWS.


Here’s what I did…

1. Setup an AWS account.
I already had an Amazon account so I was able to use that.
It’s worth setting up a billing alert so you know when you’re not on the AWS Free Usage Tier.

2. Launch an EC2 instance.
Setup a key pair for you to be able to SSH into your instance.
Setup a security group so that you can access the EC2 instance by HTTP, HTTPS & SSH.
I use my Mac to SSH into my instance. You can use the SSH key that is generated. If you are using a Windows machine to SSH into your EC2 instance, then you can use PuTTY.
Choose the location to host your EC2 instance that is closest to the majority of your WordPress users. I chose Sydney based on my Google Analytics usage.
I chose a micro instance but this requires a fair bit of tuning to get working properly.

3. Setup the LAMP server.
You will need to install Apache, MySQL and PHP. Depending on the Linux version you chose for your EC2 instance, there are a few different commands to install these.
Lock down the LAMP server.
I used the AWS EC2 guide for setting up WordPress (see AWS guide here).

4. Migrate WordPress to EC2
I didn’t do all the steps from the EC2 guide for WordPress. You don’t need to do all of the WordPress install elements if you are migrating a WordPress instance. Mainly the setup of the LAMP and creation of database tables and usernames.
If you’re not changing the URL when migrating WordPress, you can pretty much just copy your files and database over to the new server. There is a good article on the WordPress site here about migrating WordPress sites.
I used FileZilla to copy my files from my old hosting company to EC2. You can connect using your SSH key.
I used MySQL Workbench to extract the database and import it into the new EC2 table. I used a tunnel via PuTTY to connect to the MySQL port.
Make sure that your httpd.conf file allows the .htaccess redirections to work in WordPress.

5. Tune AWS EC2
You will need to tune Apache for WordPress otherwise you will run out of memory. The standard setup of Apache will pretty much take up all the memory from a micro instance.
It’s also useful to setup a swapfile to stop thrashing.

6. DNS changeover
You should associate an IP for your site by using the elastic IP option in EC2.
You can then migrate your DNS entries to your EC2 instance.



Here are some good resources that I found on how to do this.

Leave a Reply