Credit for this post goes to my mentor, Andy Cross, who walked me through my first EC2 deployment. Three cheers to Andy!!!

Amazon recently released Micro instances on their EC2 platform, which makes cloud computing incredibly cheap ($16 a month) and viable for hosting small sites. Plus your’e backed by the power of the THE CLOUD. Anyway, I’ve decided to host my blog in the cloud, in Linux!!

I run a WordPress blog because a) it’s full of features, b) it’s free c) is awesome. Even tho it’s php, as a developer, you have stick your oar into technologies outside of your comfort zone now and then. It’s been running on a Windows VPS, so far for which I pay a ridiculous sum of money, because Windows is a power hungry whore. Using the Amazon Web Services Calculator, I found then on a micro instance I could be saving over 90% on my monthly bill.

I started out with an Ubuntu 10 LAMP instance and has it running in under 2 hours, but Ubuntu has a bug with Elastic Block Stores and I didn’t really want to mess about with the work around that had been posted on various forums, so I went for Fedora box instead.

Here’s my screen by screen guide on setting up WordPress on Fedora 8 on an Amazon EC2 micro instance.

Head to https://console.aws.amazon.com/ec2/home (you’ll need to create an account if your don’t have one, oh and you’ll also need to choose where you want your servers to reside, the choice is yours) and you should be presented with the EC2 management console dashboard. You won;t have any instances set up yet, so click on Launch Instance to create one.

Amazon EC2 screen asking if you want to launch a new instance

You launch an instance with a base image (Amazon Machine Image) which will be an OS that may or may not have other software preinstalled, for example there are community AMI’s for mail servers and web servers and a whole lot more. We’re going to use the Getting Started on Fedora Core 8 AMI.

Amazon EC2 screen asking you to choose an AMI to use

Choose how many you want, which zone in the your chosen part of the world and what type. Make sure you select Micro. You can also choose you either Launch an Instance (which we want to do), Request a Spot Instance (basically request a temporary server for a specific price) or Launch it into you Virtual Private Cloud, if you have one.

Amazon EC2 screen asking you what type of instance to launch

Make changes to the Kernel and RAM Disk at your own risk

Amazon EC2 screen letting you change the Kernal and Ramdisk options

You need a Key pair for authenticating when you connect to your server over SSH. Create and download one and make sure you actually download it. You will not be able to download it again and without it you won;t be able to SSH into your instance.

Amazon EC2 screen asking you to create a key pair

A security group is what it is. You’ll want at least SSH and HTTP for WordPress. you also resuse existing groups

Amazon EC2 screens asking you to create a securing group

Confirm it

Amazon EC2 screens asking you to confirm the settings for your new instance

Done. It should only take a few seconds for you instance to launch (it depends how busy it is)

Amazon EC2 complete screen

When it is running, it should be in the manager shown as running.

Amazon EC2 instance in EC2 Manager

You need to grab PuTTY from here and extract it somewhere on your drive. Fire up PuTTYgen and Load the Key Pair (pem) file that you downloaded from Amazon. Save the Private Key (ppk) without a passphrase.

Creating a PPK from your Amazon EC2 key pair PEM

Launch PuTTY, head down to the Auth menu and select the ppk you just created.

Select the PPk key from the PuTTY Auth screen

Enter your Amazon EC2 Instance Hostname (you can find this in the EC2 Management console ) and save the session settings.

Enter the Amazon EC2 hostname into the Host Name textbox on the PuTTY Session screen

Click Open and when the warning below is displayed, click Yes.

When the PuTTY warning shows regarding uncached host keys, just click yes

A fantastic cmd screen show pop up and you can login with the username ‘root’

Connect to your instance and log in as root

Use the command ‘˜lsof -i’ to view open ports on the instance. As you can see, no port 80 is open, so we need to install Apache (and the rest of the LAMP stack)

lsof -i

Install Apache (httpd)

yum -y install httpd

Start the Apache service

service httpd start

Make sure Apache is running by checking that it’s listening on port 80

lsof -i

Browse to your hostname and you should see the Fedora welcome page!

Browser to your Amazon EC2 host name in a web browser

Install php and the mysql client

yum -y install php mysql

install the mysql server

yum install mysql-server

Install PHPMyAdmin (web client admin interface for mysql)

yum install phpmyadmin

By default, PHPMyAdmin is blocked to external IP’s, so open up the PHPMyAdmin config file using vim.

sudo vi /etc/httpd/conf.d/phpmyadmin.conf

Edit the file as per below. You need to hit the Insert key to start editing.

allow from all added to the phpmyadmin.conf file

You can’t Crtl+S to save in vim. Hit the ESC key, then :x and Enter to save an exit. For reference, ESC followed by :q and Enter will exit the file without saving (vim will also warn you if you have unsaved changes)

ESC :x ENTER

Restart Apache to pick up the changes

service httpd restart

Start mysql

service mysql start

Set the root user’s password for mysql

/usr/bin/mysqladmin -u root password 'password'

Head to http:///phpmyadmin. Log in with root credentials and create a new database called wordpress (default settings)

Using phpmyadmin to create the WordPress database

Create a new user and hit GO

Using PhpMySql to create the WordPress database user

Click on edit privileges

Using PhpMySql to select the suer to edit privileges for

From the Database specific privileges section, select the wordpress database from the drop down

Using PhpMySql to select a database to add privileges to

Click Check All and Go

Using PhpMySql to give the WordPress user all privileges on the WordPress database

And the privileges should end up looking like this

Select the Wordpres user from the privileges screen of the WordPress database

Jump back into you server and download wordpress using wget (you could use yum install to install wordpress, but it configures it in a slightly different way meaning that the only way to auto-update would be via yum, not via wordpress)

wget http://wordpress.org/latest.tar.gz

Unpack it to your html folder, it will be unpacked as /var/www/html/wordpress, meaning your the URL for your blog will be http:///wordpress but …

tar -xzvf latest.tar.gz -C /var/www/html

… you can host it at the root of your domain by moving the content into html and follow this by …

cp -avr /var/www/html/wordpress/* /var/www/html

… deleting the wordpress directory.

rm -rf /var/www/html/wordpress

We need to apply the right permissions to the html folder so that the Apache user can Write to it, but first we need to find out who the Apache user actually is. Open the Apache config file.

vi /etc/httpd/conf/httpd.conf

Find the name of the Apache user, in this case ‘apache’.

httpd.config file showing what user Apache is running as

Change the owner and permissions on the html folder

Make the Apache user owner for the html folder and give it Read, Write, Execute rights

Don’t go to your wordpress site just yet. If you do, wordpress will configure it with your EC2 hostname as the domain for the blog, and when we attach an IP to our instance (so we can point a domain at it) we won’t be able to log in (without changing the setting directly in the database, so it’s not a complete fail). head back to the EC2 management console, click on Elastic IP and Allocate New Address

Amazon EC2 screen to allocate an Elastic IP

Associate the IP with your instance. Amazon change you if you have an IP that is not assigned, so it’s best to always assign IP’s or release them completely.

Amazon EC2 screen to associate an instance to an Elastic IP

Select the instance id of the instance to attach the IP to.

Amazon EC2 screen to select the instance to associate the Elastic IP with

Attachment complete, as shown the the information panel for your instance in the EC2 management console.

Amazon EC2 screen showing Elastic IP address assigned to instance

You have to connect to your server by IP address now. Your hostname will no longer work, and if you detach the IP, your instance will be assigned a different hostname

Connecting to an Amazon EC2 instance using an Elastic IP address

Head to your blog

The starting screen for WordPress setup

Enter the database connection details

Wordpress screen for configuring the database

Database setup complete

Wordpress database setup is complete, continue to install wp-config.php

Enter you site configuration details

Wordpress site configuration screen

Setup complete!!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>