Amazon T1 Micro instance With Apache Primer

Although there's been a lot of buzz about the new Amazon t1.micro instances and the "Free Tier" for amazon, I haven't seen a good tutorial on how to just get started using the Amazon Dashboard console, so I decided to make this quick-and-dirty "get your site up and running in 15 minutes" bit. For those of you who don't know, Amazon launched a micro instance type which is perfect for most "simple" websites that don't generate a ton of traffic. If you don't need MySQL, but do need some server-side processing like PHP, this may be the solution for you.

Signing Up for the Services

First things first, head on over to http://aws.amazon.com and click the big "Sign Up Now" button.

You'll want to sign up for at least EC2 and EBS, but most other services aren't used in this tutorial.



Sign into the AWS Management Console

Everything really happens under the AWS management console, so after you've gone through the riffraft of verifying your account, you'll want to click the "sign in to the AWS Management Console" link at the top of the http://aws.amazon.com page.

Once here, you'll want to click on the "EC2" tab:

Launching your instance

Click on the "Launch Instance" button.

This wizard will guide you through launching a new instance. The key things to keep in mind here are that you want to make sure you're launching a "t1.micro" instance and using Amazon's 64 bit image.

On the next page, make sure you choose the "t1.micro" instance:


The next page you can ignore, just click continue:

The next page just lets you set some labels for your instance, in general you probably just want to at least set the "Name" tag to something in the event you launch multiple instances, you can use this to identify which is which:

For example, I chose to name mine "ApacheServer"

Setting up your Keypair

Click continue to the next page, where you'll be prompted to create a keypair. If you've done this before, you can use an existing key pair, but if you're reading this tutorial I'll assume you haven't set one up yet.


KeyPairs are how you log into your server, using SSH. It's important to note that you'll need to download this key pair and keep it in a safe place. For security reasons, you can never download your keypair again after this setup procedure.


Enter a name for your keypair and click the "Create and Download your Key Pair" link:

Setting up your Security Group

Click continue and you'll be taken to a page allowing you to set up your security group. It's generally a good idea to set up a new security group for each new "group" of servers you want to create. For example, this is for apache, so lets name it "apache" and fill out a description:

Now we see by default that SSH is authorized, but we also want users to be able to access this server via HTTP, and probably HTTPS as well. We add those in by choosing the appropriate fields from the row at the bottom:
Make sure to click the "Add Rule" button after adding each rule:

Before moving on, make sure you see something like this:

Review and launch

Now we look over our information, and make sure everything's ok before launching the instance:



After launching, you should see a page like this:



Setting up your Elastic IP

Of course, Amazon is very volitile, so we'll want to make sure we set up an elastic IP for our instance before we change over our DNS name.


On the left side of your console, you should see a link to "Elastic IPs":


Once here, you can allocate a new Address:

This requires you to confirm that you wish to allocate a new EIP.

You're currently limited to 5 EIPs per account, and you pay for any EIPs which are not associated to instances. If your EIP is associated to an instance, you don't pay for it. From here, you'll see your new EIP:



Right-click on it and choose "Associate Address":


Choose your instance:


Assign your DNS to your EIP

This all depends on who you bought your domain from. You can simply associate your domain with this IP address and your users will be forwarded along to this server automatically.


Logging in

Of course, now you'll need to log in and set up your software, specifically Apache. From a terminal or shell, use the keypair you downloaded to SSH into your instance by your elastic IP address:

$ ssh -i myKeyPair.pem ec2-user@174.xxx.xxx.xxx

You'll be greeted with a friendly banner:


       __|  __|_  )  Amazon Linux AMI
       _|  (     /     Beta
      ___|\___|___|

See /usr/share/doc/amzn-ami/image-release-notes for latest release notes. :-)


If instead you see something like this:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Then you need to first change your keypair permissions:

$ chmod 0600 myKeyPair.pem

Installing Apache

The instance you've just logged into is based on Redhat, so you've got the Yum package manager. Install apache using the following command:

$ yum install httpd
Confirm all the prompts with a "y", and continue on to setting up your apache configuration

Configuring Apache with WebDav

The easiest thing to do next is to configure your Apache server to allow you to connect via webdav. Do so by first creating an .htpasswd file for your user:

sudo htdigest -c /var/www/.htpasswd webdav myAwesomeUserName

It'll prompt you for a password, make sure this is secure since you'll be using it to gain full access to your website files.


Next you'll want to change the ownership of the /var/www folder to the apache user:
sudo chown apache:apache /var/www

Finally, set up the DAV server in a /etc/httpd/conf.d/000-default.conf file. You can use whatever basic editor you want here, but I use vim:

vim /etc/httpd/conf.d/000-default.conf

Make sure this file looks like the following:
        DocumentRoot /var/www
        <Directory /var/www>
                Options Indexes MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        Alias /webdav /var/www
        <Location /webdav>
           DAV On
           AuthType Digest
           AuthName "webdav"
           AuthUserFile  /var/www/.htpasswd
           Require valid-user
        </Location>


Starting Apache

You can start apache by simply running:
$ sudo service httpd start

Setting up your WebFiles

You can now connect to your WebServer via WebDav. Simply use the following URL, replacing with your hostname:
http://example.com/webdav/

And connect using your username and password you set up with the htaccess command. Note that this will take you directly into your web root, so feel free to deposit your index.html file directly here.
4