How and why I moved my blog to Amazon EC2 from WordPress.com

On October 30th, 2007, I launched my blog, GregsRamblings.com.  At the time, I needed something quick and simple so I went with WordPress.com, a very popular wordpress hosting site.  You can have a blog up and running in under 5 minutes.  Although WordPress.com has served me well, I’ve had a few frustrations along the way such as restricting me from using any JavaScript, Flash, iFrames, etc.  I’ve also felt limited by the relatively small collection of available themes.

Today, I re-launched GregsRamblings.com on it’s own virtual server, an Amazon EC2 instance.  The experience of moving from WordPress.com to my own self-hosted site had a few challenges, so I thought I would describe the steps involved for anyone else looking to make a similar move.

Why Amazon EC2?

Cost

There are a lot of great hosting companies that can be used to host a WordPress blog, but for me, having a virtual server made the most sense.  I wanted 100% control over the server.  Amazon recently announced a new micro-instance for about 2 cents per hour (about $15/month).  I recently blogged about my initiation into the world of EC2 and the new micro-instance here.

Scalability – being prepared for an explosion of traffic

Although my blog does ok on traffic, I don’t really worry too much about overloading my server… but, it’s nice knowing that if some major news organization mentioned one of my blog posts, I could scale up my infrastructure with a few clicks of the mouse.  Let’s imagine that I’m about to get millions of hits.  Amazon EC2 provides several options for scaling:

  • I could move from my micro-instance to one of the many larger instances and associate my assigned “elastic ip” to the new instance.  This would give me more CPU and faster I/O.
  • I could also fire up some clones of my existing instance and use Amazon’s Elastic Load Balancing feature to distribute traffic across the instances.  I like this model because it’s linearly scalable and easy to tear down after the excitement dies down.
  • It’s also worth noting that Amazon has a Auto Scaling service that can automatically scale your capacity up and down depending on conditions that you define.  This is way overkill for my blog, but it’s a cool feature.

Setting up my Amazon EC2 instance

I have a micro-instance created from an AMI (Amazon Machine Image) from Alestic.com, the home for Ubuntu AMIs.  I prefer the Ubuntu flavor of Linux mostly because I’m familiar with it.  I installed MySQL, PHP, Apache, ntp and other packages using Ubuntu’s apt-get.  Here’s the install command – sudo apt-get install apache2 mysql-server php5-cli libapache2-mod-php5 php5-mysql unzip zip ntp

I also enabled the following Apache mods — rewrite (required for permalinks to work), headers and expires (required for the WordPress caching plugin).

Setting up WordPress

I then installed WordPress using the installer at http://wordpress.org.  The install process was amazingly simple.  It prompts you for a few settings (database location, user, passwd, blog name, etc.) and then you’re good to go.

Themes

The hardest part of this whole experience was choosing a theme!  There are literally thousands of amazing themes to choose from.  Here are a few sites that I found to have some good choices:

There are many other sites offering great themes so you could spend several days browsing.  I was looking for a theme with a clean and simple look free of bells and whistles.  I finally settled on the Mortar theme from WooThemes.  WooThemes and several of the other sites offer a free sandbox to test drive the theme.  I spent a couple of hours taking advantage of this to confirm that the theme offered all of the features I required.

Plugins

One of the first things I noticed when I went to the administrative pages of my new WordPress installation was that many of the menu options I was accustom to were missing!  This is because WordPress.com had many installed plugins.  This led me on a plugin chase!  Below are the plugins I installed:

  • Akismet – protects your blog from spam comments.  Don’t skip this one!
  • Google Analytics for WordPress –  This plugin makes it simple to add Google Analytics to your WordPress blog.  I could have easily added the code myself, but the plugin guarantees that it’s in all of the necessary places which saves me from some work.
  • Google XML Sitemaps – auto-generates a sitemap.xml (and sitemap.xml.gz) for your entire blog and updates it every time a post is published.
  • Subscribe to Comments – Allows readers to receive notifications of new comments that are posted to an entry.
  • SyntaxHighlighter Evolved – provides syntax highlighting of source code.  Lots of great features.
  • WordPress.com stats – Tracks views, post/page views, referrers, and clicks. Requires a WordPress.com API key (free). This will give you the same stats screen that you have on WordPress.com.
  • WordPress Database Backups – On-demand backup of your WordPress database.  You could easily do a mysqldump, but this makes backups a mouse-click away while in the admin console.  You can also schedule hourly, weekly, etc. backups.
  • WordPress Importer – You’ll need this if you plan to import data from another blog.
  • wp-Table – This plugin is a simple table manager with buttons for adding new rows, columns, etc.  A good time-saver
  • WP Super Cache – If your blog gets any decent activity, you’ll want this.  It generates HTML files that are served directly by Apache without processing PHP scripts.  I’ve read multiple accounts of people’s blogs getting unresponsive after being mentioned on Techmeme, Techcrunch, etc.  This plugin will dramatically increase the amount of traffic your blog can handle.

Moving from WordPress.com to my new server

Moving the data (posts, pages, users, tags, etc.)

This part was simple.  I used the WordPress export feature to generate an XML file that contains all of my stuff.   I then logged into my new server and imported the file (requires the WordPress Importer plugin mentioned above).  NOTE:  If your new blog is going to have a different URL than your old blog, you should do a search and replace on the XML file before importing it.  Otherwise, you’ll have to do some database surgery (see below).

Hostname and DNS challenges

I had a custom domain on WordPress.com (GregsRamblings.com).  Obviously I wanted to have my new blog up and running before I turned off the old blog, so I needed to have it running in two different places simultaneously.   WordPress uses full URLs for everything in the database so all of my images, posts, etc., were  stored as “http://gregsramblings.com/….”.   For me to test anything, I would need to make the server think that it was gregsramblings.com and I also needed to make my laptop computer think that gregsramblings.com points to my new server.  In order to do this, I added a new entry to the /etc/hosts file on both the server and my laptop (if you are on Windows, you’ll need to add an entry to c:\windows\system32\drivers\etc\hosts).  Now I was able to finish customizing and testing.

My domain, gregsramblings.com, was originally registered with WordPress.com.  In retrospect, I should have registered it with my own chosen domain provider such as 1and1.com, register.com, godaddy.com, etc. so I would have full control over the ip address mapping.  Wordpress’s nameserver management system does allow you to add new hosts but it does not allow you to change the main “A” record that points the domain to a specific IP address.   WordPress does allow you to change nameservers so you can at least let another nameserver handle your mappings.  I chose to move the domain to 1and1.com which surprisingly only took 48 hours from start to finish.

Here is a summary of the steps I took to move the domain:

  • Logged into WordPress.com and went to the domain management screen and unlocked the domain.  Unlocking the domain allows it to be transfered away.  Make a note of the authorization code (needed in next step)
  • Logged into 1and1 and initiated the transfer of the domain and entered the authorization code received in the prior step
  • Once the domain showed up on the 1and1 console, I immediately mapped gregsramblings.com to my new IP address.
  • Logged back into WordPress.com and changed the nameservers to 1and1.com’s nameservers (in my case it was ns51.1and1.com and ns52.1and1.com)
  • At this point, both the old domain provider and new domain provider were using the 1and1 nameservers. (note – it takes a few hours before things start taking effect)
  • I later received an email instructing me to login to workpress.com and approve the transfer.  At this point, no other changes to the domain are allowed on wordpress.com because the transfer has been initiated.

Wrapping up

The rest of the work was tweaking css, php and configuring plugins.  As I was going through most of my posts, I found a few problems that were easily resolved:

  • There were several posts with embedded videos.  WordPress.com does not allow any <embed> tags so you have to use their video plugin syntax.  I spent a few minutes trying to find the same video plugins, but quickly realized that it was easier to just replace the tag with an actual embed tag.  I prefer to use the direct embed tags anyways.
  • When I first started my blog, it was referenced as gregorywilson.wordpress.com, so several of my older posts pointed to URLs with the wrong hostname.  I used the following SQL to correct this (gotta love the REPLACE function in MySQL!):
    UPDATE wp_posts SET post_content = REPLACE(post_content,”http://gregorywilson.wordpress.com”,”http://gregsramblings.com”);
    UPDATE wp_posts SET guid = REPLACE(guid,”http://http://gregorywilson.wordpress.com”,”http://gregsramblings.com”);
  • For some reason, some of the source code used in my blog posts got encoded so “<mx:Button/>” turned into “&lt;mx:Button/&gt;”.  I never figured out why some posts had this issue but others did not but I was able to fix it with the following SQL (I did this on a post by post basis to be safe):
    UPDATE wp_posts SET post_content = REPLACE(post_content,”&lt;”,”<”) where ID = 185;
    UPDATE wp_posts SET post_content = REPLACE(post_content,”&gt;”,”>”) where ID = 185;
    UPDATE wp_posts SET post_content = REPLACE(post_content,”&quot;”,’\”‘) where ID = 185;
  • I realized a few hours after going live that my server was not setup to handle outbound email, so I was not getting notifications on comments, etc.  For basic SMTP email, I prefer postfix.  I installed with:  sudo apt-get install postfix — It’s very important that your server block external access to the SMTP port (port 25).  Amazon EC2 blocks everything by default, so it will only be allowed if you specifically allow it.
  • I’ve considered adding one of several plugins/themes that provide a light-weight version of the blog to mobile devices, but from my own experiments, the current theme works really well as-is.

One final note – WordPress is also great for non-blog websites and there are of course themes available for about any type of site.  I recently upgraded my local airport’s website from this basic HTML site to this Wordpress site.   The new site is using the “destination” theme from Templatic.  This is a great example of how to use a good designer! ;)

Show Comments

Hide Comments

Comments are closed.