Skip to content

Self-Hosting a Small WordPress Blog or Website on Amazon EC2

Last week, as part of my effort to move my domains away from godaddy.com, I decided to move this blog.  That move is complete and what you are looking at is now hosted on an Amazon EC2 “instance”.  What follows is my experience and notes on the costs of doing this.

The Costs

First off, on a 3 year hosting plan at Godaddy, I was paying about $3.20 per month, which is very very cheap.   You cannot get that price directly, but I had some coupons.  A more normal cost for Godaddy is about $5.00 per month.   My final costs for my new hosting solution on EC2 are:

  • First year: $0 per month.
  • Next 3 years: $ 6.43 per month, plus bandwidth (mostly free, unless I hit the front page of Reddit).

This is not as good as Godaddy, but it is a very acceptable rate to me (given I have complete root access to the machine and can do anything I want with it).

Below is the analysis of the EC2 costs.  For reference, here is a link to the EC2 pricing sheet.  My costs are for the us-east Amazon region – costs in other regions are different.

  • First year:  Amazon gives away one t1.micro instance plus bandwidth to new AWS customers for the first year.  This is why the first year is free.
  • Next 3 years:  $100 for 3 years of “Heavy Utilization Reserved Instance” (t1.micro), plus $0.005 per hour ($43.80 per year), do the math and that comes out to $6.43 per month.
Without the reserved instance purchase, the cost would be $14.60 per month – significantly more.   Don’t make the same mistake as I did – wait for your free year to expire before purchasing the reserved instance!   (Aaargh!  Actually, its not so bad for me because I plan on having more instances, so the free tier was never going to be enough).

Actually doing the move – the easy way

[UPDATE: I have posted a short YouTube video on how to do this]

The first step was to go into my existing WordPress blog and do a complete export of my posts and pages (Tools/Export/All Content).  With this downloaded to my local machine, I felt ready to get going.

WordPress boasts a “famous 5 minute install”, but don’t be misled by that – it can be done, but that depends highly on your Linux skills.  The PerfectAPI vision is to make things simpler, so I have for you the following, with all my experience of doing the move baked in.  Skip to “the hard way” further down in this post if you like it that way.

  • ami–e5e6328c – a us-east Amazon EC2 Ubuntu 11.10 EBS image that is set to go with what you need.  Assuming you are already signed up and have some experiencing using ssh with Linux machines on EC2, this should give you something close to the 5 minute install.

To start with the image above, first launch it into a t1.micro instance.  Be sure to use a security group that allows port 80 (http) access, and one that allows SSH access (port 22).  Once the image is running,  ssh into it using a tool like Putty.  A reasonable & quick guide to using Putty for this purpose can be found here.  Note that the login name for the instance above is “ubuntu, not “root”.

Once logged in, install WordPress by executing the command:

sudo ./install.sh

(This is my custom install script).  Installing in this way ensures your instance has its own unique passwords for mysql and wordpress (not the same as everyone else using the above image).

Once the install completes (10 seconds), go the the AWS console and set yourself up an “Elastic IP”.  (An elastic IP is just a public IP address that you can point your domain at).  Associate your new Elastic IP with your new instance.    Then, go to your blog at:

http://your-elastic-ip/

…and complete the WordPress setup.  Use Tools/Import/Wordpress to re-import all of your posts and pages.  Setup your theme, play with your widgets, install some plugins.   Do not change the url of the blog in your General Settings until you are ready to switch over.  Failing to heed this advice will make the new blog redirect to the old whenever you login.  Very annoying and difficult to change back.

Final step is to switch your domain records – use whatever tools your DNS provider has to point your domain at your elastic IP address.  After that, you can set the correct URL in the General Settings of the new blog.   It can take a while before DNS changes kick in – if you’re impatient, you can temporarily edit your hosts file to see the changes early.

Put a note on your calendar for 1 year after your Amazon AWS signup date, to purchase yourself a reserved instance, so that the lower pricing kicks in.

Doing the move – the hard way

The first trick for getting any new instance up on Amazon is to find a base AMI image that you like.  I like the Ubuntu images  at Alestic, so that is where I started.  After creating an image with an instance, you have a way to go before you can even get started on WordPress, for example you need to install a LAMP stack (apache, mysql, php), you want to ensure the instance stays up-to-date with linux security patches, etc.  Anyway, I created scripts to be able to do all of this in a repeatable way, and they can be found on my amigenerator project on Github.

If you need, here is a direct link to the scripts.  The scripts only work when run from the ami-generator tool, so looking at them on Github is mostly for education.  The ami-generator tool itself is still in alpha stage, so I am not going to include instructions on how to install/use it here.

My advice – just do it the easy way instead.  (But if you do have suggestions on how to improve the scripts, please do let me know).

 

 

Introducing… amigen node.js package

This project is still very much a work-in-progress, but it is far enough along that I have published it.

What it does is provide a framework for creating predictable, pre-installed machine images on Amazon EC2 (the Amazon cloud). My motivation for doing this is to assist those people that don’t necessarily want to get into all the dirty details of creating and maintaining linux images. They just want something that is pre-configured to their specification.

The project is hosted at github.com.  Usage requires some knowledge of node.js.

Features so far include:

  • images automatically install security updates
  • various common software can be installed

That’s all for now…

Introducing… Pokki Pomodoro Timer

For fun, and for a chance at winning $30K, I created this small Pokki app. Please download and enjoy!

Download Pomodoro Timer for Pokki

A Pomodoro timer is just a little countdown-timer that helps you manage your time by breaking up work into 25 minute chunks.


While the timer runs, it also shows in your taskbar with the number of minutes remaining…


…and when its done, it plays a little egg-timer sound to let you know its time to take a short break.

Download Pomodoro Timer for Pokki

Intro to Perfect API

As it states in the About page, the vision of Perfect API is

…to simplify the act of programming

The first step in doing this will to create an ecosystem that will enable better code reuse across projects, both open source and closed source.  To do this, we propose a change to the way we construct software, by introducing some new fundamental building blocks.

Right now, we’re working on defining and prototyping those building blocks. We’ll post more on this blog as we get nearer a beta release.

 

The difficult blue eyes logic puzzle

See also xkcd version, or on wikipedia. I found the original link on Damien Katz’s blog. Its difficult to me, because there is a widely accepted solution that I could not grasp for quite some time. The wikipedia link includes the solution. Read one of the others if you just want the problem.

Here is the puzzle, followed closely by the solution:

On an island, there are 100 people who have blue eyes, and the rest of the people have green eyes. If a person ever knows herself to have blue eyes, she must leave the island at dawn the next day. Each person can see every other persons’ eye color, there are no mirrors, and there is no discussion of eye color. At some point, an outsider comes to the island and makes the following public announcement, heard and understood by all people on the island: “at least one of you has blue eyes”. The problem: Assuming all persons on the island are truthful and completely logical, what is the eventual outcome?

The accepted solution is that all of 100 the blue eyed people leave the island after 100 days. The short, misunderstood explanation is that the outsider introduced some “common knowledge” that was not there before, which allowed all the blue-eyed people to deduce their eye color.

The proof uses induction, and goes like this. If there were only 1 blue-eyed person (n=1), then he would see that there are no other blue-eyed people, and deduce that he is the one person the outsider mentioned. We would leave the island. If there were 2 blue-eyed people (n=2), then they would both see the other and expect the other to leave on day 1. When neither leaves the island after 1 day, they will each realize that they must be the “other one” with blue eyes, and leave together on the day 2. Using induction, bla bla, 100 days later all blue-eyed people leave.

Lets look at that more closely.

The argument works for day 1. Fairly obvious. Blue eyed person sees no other blue eyes, so he knows he is the one and leaves.

The argument still works for day 2. At first it seems the 2nd blue-eyed person has no reason to assume he is the “other one”. But he knows that there is more than one (one would have left after 1 day), but he can only only see one (so he must be the other).

Consider a green-eyed person on day 2. He would also know that there is more than 1 blue-eyed person. But he can see 2 blue-eyed people, so he will do nothing. He will not know that he has green eyes – he will simply reserve his judgment until day 3.

Eventually day 100 comes (induction allows us to jump forward like that), and all blue eyed people are confronted with the inevitable truth, and they leave.

Further truths:

  • The 1st day pronouncement that someone has blue eyes appears to add no new knowledge. This is true for everything except the simplest case of a single-blue eyed person. The pronouncement is a device to assist in the induction proof. Really, they would simply leave 100 days after they got there, no outsider pronouncement necessary. (That is just harder to explain/prove).
  • In some versions of the puzzle, the person has to know their eyecolor to leave (the example above is limited to blue). In those versions, if all of them know there are only 2 eye colors, then on day 101, all green eyed people will leave too. They would leave earlier if there were > 1 of them and < 100, and then the blue eyed people would leave one day later.