Wordpress at Amazon For $10 a Month

Introduction

With Werner Vogels’ announcement that he had moved his blog to S3, I thought it was high time to take my blog to the cloud. Up until this week, High Tech in the Hub has been hosted on a virtual private server at my favorite VPS provider (Linode). But with last September's launch of micro instances, the cost effectiveness of using Amazon as a low-cost hosting provider has never been better.

So for today's post, I am outlining how to run your blog in the cloud.  The steps are targeted at an Amazon novice with some basic Linux and Wordpress experience.

Configuration

I chose an Amazon micro instance, which is configured with 613 MB memory, provides up to 2 EC2 compute units, and supports 32 or 64-bit. I chose 64-bit Ubuntu Linux 10.10 for an operating system, MySql 5.1 for a database, Nginx 0.7 for a web server, and decided to run Wordpress 3.0.5.

Costs

My goal was to stay under my current monthly cost of $20 per server at Linode. Unfortunately the Amazon pricing model has all the complexity of a Wall Street derivatives trading algorithm, so making sense of it requires a little patience. The simple version is this: there are effectively three ways to purchase your instance - on-demand, 1-year reserved and 3-year reserved. You pay separately for your instance and storage per hour used, and network traffic per GB.

Below is a table describing the costs for the three available options:
[table id=8/]

  • Costs are approximate, and monthly cost includes the amortization of the pre-pay (if applicable)

I decided to go with a 3-year reserved purchase to get my monthly cost to approximately $10 per month.

Setting Up Amazon Account

Prior to installing Wordpress, you will need to sign up for an Amazon EC2 account. Robert Sosinski provides Mac users a great step-by-step tutorial on getting started with EC2, which I highly recommend. If you do not follow these instructions, you will need to ensure you have:

  • Setup an EC2 account
  • Installed the Amazon API, which includes command line tools used below
  • Created public/private key pair for secure usage of API

Installing Wordpress

The below steps will take you through the steps of launching, configuring, and installing Wordpress on your instance. The total time to follow the below instructions is about 30-45 minutes.

  1. Launch your Amazon instance

$ ec2-add-keypair my-ec2-keypair $ ec2-run-instances ami-cef405a7 -k my-ec2-keypair -t t1.micro

Note: my-aws-cert is the name of your keypair, and ami-cef405a7 is an AMI from Ubuntu.com (it comes with an 8 GB Elastic Block Storage volume).
2.  Authorize both Web and SSH access to your instance

$ ec2-authorize -p 22 $ ec2-authorize -p 80

  1. Login to your newly launched instance

$ ssh -i ~/.ec2/certs/my-ec2-keypair.pem ubuntu@ec2-192-168-1-1.compute-1.amazonaws.com

Note: ec2-192-168-1-1.compute-1.amazonaws.com is the public DNS address of your instance, which can be identified by either running ec2-describe-instance or using the AWS Console.

  1. Update package manager

$ sudo apt-get upgrade $ sudo apt-get dist-upgrade

  1. Get packages, including Nginx, MySql and PHP

$ sudo apt-get install nginx mysql-server php5-cgi php5-mysql phpmyadmin

  1. Install & config SpawnFCGI

$ sudo apt-get install spawn-fcgi $ sudo pico /etc/init.d/php-fastcgi $ sudo pico /etc/default/php-fastcgi $ sudo chmod +x /etc/init.d/php-fastcgi $ sudo /etc/init.d/php-fastcgi start

Source for files edited above can be found here: /etc/init.d/php-fastcgi and /etc/default/php-fastcgi

  1. Download Wordpress

$ cd /tmp $ sudo wget http://wordpress.org/latest.tar.gz $ sudo tar -xzvf latest.tar.gz $ sudo mv wordpress /var/www

  1. Create database

$ mysql -u root -p

From within the mysql session run the following:

mysql> CREATE DATABASE wordpressdb; mysql> CREATE USER wordpressuser; mysql> SET PASSWORD FOR wordpressuser = PASSWORD(‘password’); mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO wordpressuser mysql> FLUSH PRIVILEGES

  1. Configure nginx

$ sudo pico /etc/nginx/wordpress.conf $ sudo pico /etc/nginx/nginx.conf $ sudo mkdir /var/www/wordpress/log $ sudo /etc/init.d/nginx restart

Source for above files are found here: /etc/nginx/wordpress.conf and /etc/nginx/nginx.conf

  1. Configure Wordpress

$ sudo cp wp-config-sample.php wp-config.php $ sudo pico wp-config.php

Fill in DB_USER (e.g. wordpressuser), DB_PASSWORD and DB_HOST (e.g. localhost)

  1. Direct web browser at site to finish the standard Wordpress install

Other Considerations

Assuming you have a domain name, you'll also want to assign a static IP address (a.k.a. Elastic IP) and switch your DNS to your new instance. You can do the former from the AWS Console, and the latter with your DNS provider.  You can also use the AWS Console to reserve an instance to realize the pre-pay discount. The discount should immediately apply to your instance, but only if you ensure you select the same instance type and region.

If you are migrating an existing blog, you might consider using the EZPZ OCB plugin to backup your existing site and then restore it to your new instance.  To enhance security, you should also add rules to iptables to filter unwanted traffic.

One last thought: you can also look to use EBS snapshots periodically to backup your instance.  It provides a fast and easy way to manage full and incremental backups of your site.