Migrating WordPress from Amazon Linux to Ubuntu

I would recommend Amazon Linux image to anyone but those who really need to use like me. Amazon Linux image comes with nearly everything what you need and supporting EBS by default. However, Ubuntu is handy if you are familiar with its architecture and already made your hands dirty around the files and setting there. You can bring over lots of your local Ubuntu experience when you work with the one on cloud.

Here’s the steps.

  1. Launch Ubuntu on Amazon EC2
  2. Set up WordPress environment on Ubuntu
  3. Backup from old WordPress on Amazon Linux
  4. Restore to new WordPress on Ubuntu
  5. Switch DNS from old to new elastic IP

Step 1. Launch Ubuntu on Amazon EC2

Leverage the community’s work on the pre-configured Ubuntu image for Amazon EC2. You can click on the list of images on the right-side bar. Unless you need the instance on the region closer to the core users, hosting one on US East (Virginia) is usually offering the lowest charge.


Clicking on the right arrow will lead to the Launch Instance page on Amazon EC2. Please select the key pair that you’ll use for this instance (if there’s existing one, you can share the same) and configure the rest. Pretty much everything is fine with the default. Launch instance.

From Elastic IP Address menu on the left of Amazon EC2, allocate new address that you’ll associate with the newly launched instance. Please note that the allocated new address will start incurring charge. If you want to save some $, you can leave this for later to come back and you can continue working with Public DNS ID that Amazon associate for the launched instance. You can access the instance using the Public DNS ID that look like “ec2-54-225-184-174.compute-1.amazonaws.com” for example.

 2. Set up WordPress environment on Ubuntu

Firstly, you’ll start installing necessary modules to the launched instance. Please login to the Ubuntu instance using ssh with the paired key. The command is:

: where public key file is the paired key that you specify when you launched instance, and the IP address is the associated on Amazon EC2. You may use the Public DNS (ec2-xxxxxxxxx…) instead.

Install Apache web server, WordPress, MySQL

I’m setting up WordPress files below /usr directory, so setup symbolic link from /var/www to there.

You can check if the symbolic link working by typing the following command:

Setup WordPress database into MySQL

The command will setup several table sets under database called “wordpress”. Now the database is ready to be filled with the migrating data. The data contains all the articles, tags, etc.. the core set of your work.


Step 3. Backup from old WordPress on Amazon Linux

From WordPress Dashboard, use [Database] – [Backup DB] or [Manage Backup DB] to export the latest export into SQL format. The exported data is gunzipped with the extension of gz. You scp over to the Amazon Ubuntu by the following command.


Step 4. Restore to new WordPress on Ubuntu

After login to Amazon Ubuntu, type the below to extract the file.

The data is complete. Now, if you’d also like to bring over the theme, etc.. besides the articles and those data, you can tar package the WordPress directory and extract it on the installed WordPress directory. This is simply a copy & paste.

Visit the elastic IP address or the given Public DNS ID from browser if the migrated WordPress site shows up. If it looks good, it’s good time to switch from the old to new site.


Step 5. Switch DNS from old to new elastic IP

By now, it’s good time to allocate a new address. Visit the DNS service provider that you are using, and point from old IP address to the new address. It’ll take a little while (5~30 mins for me) to reflect the change.

Visit again the WordPress site, see if the links works, if you can post the new article, etc..

If the parma link doesn’t work for you (i.e. clicking on the url from the front index page ends up with 404 Not Found), you may check mod_rewrite and .htaccess settings. On Debian package, the setting can be done differently from Amazon Linux.

Leave a Reply

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