How To Series: So you want free web hosting on Amazon EC2?

Do you have a bit of technical know-how or at the very least the willingness to try and acquire some? Want free web hosting on enterprise level servers with best in class infrastructure and bandwidth? Well then, keep on reading and I will tell you how to get some using Amazon’s EC2 (Elastic Compute Cloud) via AWS (Amazon Web Services). I’ll also tell you how to setup your DNS using Name.com‘s DNS management in order to point your domain to your shiny new hosting environment.

 

First of all, for those of you that do not already know, Amazon offers a myriad of cloud based products through their AWS platform. Hosted in the same environment and on the same infrastructure that hosts the universally famous Amazon.com e-commerce website, AWS truly provides a top notch service that anyone can use for just about any online purpose imaginable. What we are going to focus on in this article is setting up a virtual private server that you can use to host your domain on, for free.

 

Amazon offers a free usage tier of services for first time customers for up to one year. Yes, you will need to be a new AWS user in order to take advantage of this offer. Once the year is up you will be charged the normal price for the services you use. For a micro instance the fees are quite nominal and you will also have much more flexibility, should you want it, over a shared hosting environment. However, even if you do not qualify for the free tier you will still be able to use these instruction in order to setup your own hosting environment if by some chance you do not know how.

 

If you happen to have some Linux experience most of this will be a breeze. If you don’t, put on your safari hat and khaki pants because you’re about to go on an adventure. Ok then, lets get started.

 

Warnings

There are a few warnings that I want to get out of the way before we get started:
  • The free usage tier does have some requirements that you must meet. If you do not meet those requirements or you use more than allowed you will be charged.
  • EC2 by default uses dynamic IP addresses. This means that each time you restart your instance the IP address changes. Static IP addresses are available but they do cost a small amount of money.
  • EC2 disk storage by default is volatile. This means that when the instance is shut down either accidentally, by Amazon, or purposefully, any data being stored on it will disappear forever. There are backup mechanisms and ways of creating persistant storage but they cost money and require more advanced administration than will be covered in this article.
  • A micro instance is Amazon’s smallest instance in terms of CPU, memory, and disk space. It is more than adequate for testing, most personal websites, and probably most small business websites. If it ends up not being enough to fulfill your particular requirements a larger instance that costs money would be needed.
  • We are not responsible for any fees you may incur or havoc you may cause.
Step One: Setup your AWS account.
  • Go to http://aws.amazon.com/ and click the button on the right side of the screen that says “Sign Up Now”.
  • If you already have an Amazon account you can login using your current credentials. If not, choose “I am a new user” and click the sign in button to create a new account. You will go through a typical account creation process that should be pretty self explanatory.
  • They will ask you for billing information. You will have to enter this information in order to create your free web hosting virtual server. The reason for this is in case you happen to use more than what is allowed for the free tier or use any additional services that do happen to have a fee associated with them.
  • After you go through a verification process, I recommend the phone verification method, it will generally take a couple of minutes before you receive an account activation email. Once you receive the email you can go to http://aws.amazon.com/account/ and begin managing your account. Now the real fun begins.

Step Two: Navigate Your Way To The Management Console

  • First, make sure you are at http://aws.amazon.com/account/.
  • Click on the “Manage Your Account” link. It’s the bottom option on the left. You will probably be asked to login which you can now do using your current Amazon account or the one you just created. From this point forward if you are asked to login again, do it.
  • You should now be at the “Manage Your Account” screen and there should be quite a few options shown under “Services You’re Signed Up For”. Ignore all of that and go to the “My Account / Console” drop down on the top right side of the screen and select “AWS Management Console”. Alternatively you can just click here, which we could have done at the beginning of this section but I wanted you to see the “normal” way of getting there. Once all is said and done you should see something resembling this:

Step Three: Firing Up Your Instance

  • In the EC2 world your servers are called “instances.” You should currently be at the “AWS Management Console“. On the top there are multiple tabs. The one we are interested in is labeled EC2. Click it.
  • Since this is a new account you should see a little message telling you that you have no running instances followed by a button that says “Launch Instance”. Click that button.
  • From the “Request Instance Wizard” choose either “Basic 32-bit Amazon Linux AMI…” or “”Basic 64-bit Amazon Linux AMI…”
  • Make sure you have 1 in the “Number of Instances” box and that “Micro…” is selected from the “Instance Type” drop down. You can choose a particular “Availability Zone” if you want but for now it’s easier to just leave it set as “No Preference”. Click the “Continue” button.
  • Leave everything set to the defaults and click the “Continue” button again.
  • To the right of “Name” enter a name for your instance. You can leave this blank but if you ever decide to startup more instances this is a handy way to keep track of them.
  • Now things get tricky, you need to create a key pair in order to securely log into your server. You can also use this key pair for other future servers that you may launch in the future. Enter a meaningful name and click “Create & Download your key pair”. Save it to a place where you will not forget it and make sure you keep it secure. If someone has this key they can log into your instance and do bad things. I’ll leave the actual act of securing the key as an exercise for the reader. For now, lets keep moving and click the “Continue” button.
  • A security group is a set of firewall rules for your instance. In our case we want port 22 for SSH and port 80 for HTTP opened up. Port 22 should already be in the set of existing rules that are shown in the blue box:

    To add HTTP select “HTTP” from the “Create a new rule” drop down box and then click the “Add Rule” button. Now we can login via SSH and view web pages over port 80. Click the “Continue” button.
  • You should now see a confirmation window that shows all of the settings for your shiny new instance. Click the “Launch” button and then click the “Close” button when the next window shows up.
  • After being in the “pending” state with a yellow light for a few seconds your instance will eventually show up as being in the “running” state with a green light:

    Green light means go, so lets go!

Step Four: Logging Into Your Instance

  • Now you have a running EC2 micro instance that should qualify for the free tier of services. Remember though, if you use above and beyond the free usage tier, you will be charged for those services and amounts that do go above. It isn’t much though, so even if you do get charged it’s not too bad.
  • Click on your instance in the management console and the bottom of your browser should show some important information about your instance. Find the value labeled “Public DNS”. This is the external hostname of your instance and you will need this to login.
  • As stated in the warnings, your instance has a dynamic IP address by default. You can add an “Elastic IP” to make it static but it does cost a small amount of money. There is an “Elastic IP’s” menu option under “Navigation” should you want to play around with this feature.
  • Remember that key you downloaded? You’re going to need it now. Depending on whether or not you are on Mac, Windows, or Linux the application you use to login will be different. For Mac and Linux you will probably use SSH and it is probably already installed. If you are on Windows I recommend using PuTTY. For PuTTY on Windows checkout this tutorial on how to setup PuTTY using the EC2 key you downloaded. For SSH simply issue the following command using the path to your key and the IP address or external hostname of your instance: ssh -i PATH-TO-KEY ec2-user@IP-OR-HOSTNAME
  • Beyond what I just wrote I’m going to leave figuring out how to login to your EC2 instance up to the reader. There is a lot of information on the Internet about how to do just that. When you do successfully login you should see something like this:

Step Five: Setting Up Your Instance

  • I’m assuming that at this point you have successfully logged into your instance. Now we are going to install some basic software for hosting a basic website using the LAMP (Linux/Apache/MySQL/PHP) stack.
  • From the command line issue the following command: sudo yum -y update; sudo yum -y install httpd php mysql mysql-server This will update the software on your instance and install the basic LAMP stack.
  • From the command line issue the following command: sudo /etc/init.d/httpd start; sudo /etc/init.d/mysqld start This will start up the MySQL database and the Apache web server.
  • From the command line issue the following command: sudo chkconfig httpd on; sudo chkconfig mysqld on  This will make it so that your web server and database will restart after a reboot.
Now you have an EC2 micro instance running the LAMP stack. Find the external hostname for your instance, enter it into a web browser, and you should see the Apache welcome screen with basic instructions on what you can do next:

You can install WordPress, Drupal, or almost any other PHP based application.

 

Step Six: Setting Up DNS Via Name.com
  • Log into your Name.com account and navigate to the DNS management section for the domain you would like to point to your instance.
  • The easiest thing to do is simply create a CNAME record for *.YOURDOMAIN.TLD and just YOURDOMAIN.TLD. Under the “Record Answer” section put the external hostname of your instance for both CNAME records.
  • Alternatively you can ping the external hostname, get it’s IP address, and create A records using the IP address as your “Record Answer”. You would want to do this if you have other records on that domain such as MX records for email.
  • Properly setup DNS using CNAMEs will look like this under DNS management:
  • Once your DNS is setup and propagated (usually within 5 – 10 minutes) you will be able to get to your webpage and instance via your domain.

Bonus Stuff

  • Want to make it so that you never have to go through all of that again when creating a web hosting instance? Right click on your instance in the AWS Management console and select the “Create Image…” option. This will put it under your “IMAGES” -> “AMI’s” section of the “Navigation” menu. In the future you can simply right click on the image and select “Launch Instance”. If the content of your site rarely changes this could work well for your backup solution. The image will use storage space at Amazon and may incur some nominal fees.
  • As we already mentioned the storage on a default instance is volatile. You can use the “Elastic Block Storage” service to create persistant storage. I won’t go into details here but searching for “how to create and mount elastic block storage” on Google will yield all sorts of how to results. You will need to remap your Apache and MySQL configurations as well in order to make that data persistent but for a real world server you will probably want to do just that. The additional storage does have a price but it is more than reasonable.
  • If you need to know more remember that Google is your friend.

If we get some requests from you all and these sorts of posts seem popular we may do future articles on how to install various applications and do more using your instance. Should Name.com offer easy one click EC2 instance setup for various web services? Let us know!

  • Jorge Tellez

    Great post. Would like to see more of these in the future!

  • Nile Hadwards

    I think this article is really good for beginners, who just started to learn abut webhoting in amazon EC62. It is just the surface information.

  • Alex Farrington

    Great article and a good read too!

    Just a heads up on the Elastic IP Addresses – you only ever get billed for these if you are NOT using them. i.e. if you allocate an address and then don’t associate it with an instance. If you’re using your EIP, you don’t get billed.

  • http://twitter.com/ArnavTechnosys Arnav Technosys

    Hi, I am trying to connect with amazon with command ssh -i PATH-TO-KEY ec2-user@IP-OR-HOSTNAME but its give me error :Permission denied (publickey) what is problem ??

    • http://twitter.com/owenborseth Owen Borseth

      This question may seem silly but I just want to make sure; are you replacing PATH-TO-KEY and IP-OR-HOSTNAME with real values? If so, the permissions on your key may be too relaxed. Try this command: “chmod 600 PATH-TO-KEY” and then try connecting again with: “ssh -v -i PATH-TO-KEY ec2-user@IP-OR-HOSTNAME”. The -v option will give us a lot more debugging info to go off of. If you still don’t connect, copy the output including the command you issued to connect and email them to me at “owen AT name DOT com” and I’ll see if I can figure out what’s going on.

  • Daniel K

    Great post. I’m new to this, and I followed your steps exactly. I upload a HTML file to the /var/www/html, but for some reason i still see the Amazon Linux AMI Test Page. Any ideas ? Thanks in advance.

  • http://www.facebook.com/profile.php?id=32757 Tom Tran

    Thanks for this tutorial! I was trying to understand how this AWS thing worked and this was the most helpful thing I’ve found!

  • Tony

    Great article. Finally got this setup!

  • http://www.facebook.com/meehoo.jones Meehoo Jones

    Definitely, do the domain name to ec2 thing, that would be hot!!!

  • Chris Fargen

    I cannot thank the author enough for publishing this post. You walk the reader through the process with such great detail that even readers with limited command line experience can learn to set up their own low-cost web server! YOU HAVE FREED ME FROM IPAGE HELL! Thank you thank you thank you!!!

    • ooboo

      Just happened to stop by here to reference the article. I use it pretty much every time I fire up an instance so I can copy and paste the commands. I’m the author, and you’re welcome :)

  • Nick

    Awesome post! I would love more EC2 related articles.

  • Chris Fargen

    From above: “Once the year is up you will be charged the normal price for the services you use. For a micro instance the fees are quite nominal and you will also have much more flexibility, should you want it, over a shared hosting environment.”

    If you are wondering what the nominal fee after the first year (free), it could start at about $15 a month without the bells and whistles. You can estimate it here: https://planforcloud.rightscale.com/deployments/69151/servers/new

  • Madhab Jha

    EmailOcean is a brand new platform to cater to your email marketing needs.

    It provides promotional emailing at an amazingly low rate of $0.10 per 1000 emails. The customer only pay for what is utilised. The brilliance of EmailOcean lies in it making the process easier and faster for the customer,as compared to Amazon and Sendgrid, EmailOcean has a beautiful Web-app which makes creating and sending the campaign a lot more easier. Using this web-app one can also send and track their campaigns.

    As of now,the registrations are open by invitation but register yourself with the website and keep self updated as to when they are open to all or for your surprise invitation code.

    http://www.emailocean.com

  • Fausto Ruiz M.

    Hi! Great article! i think that I’l have no problems setting my EC2 Services for my website. But I have a question, as Free Tier users we get 750 hours of Linux and Windows Micro Instances each month for one year. Is that enough to keep running a personal site 24×7? Something like a wedding website.

    • oborseth

      Yes it is. They’ve specced out the free tier so that you can run it 24/7 for 365 days.

      - Owen

  • http://www.joshuascottmccullough.com/ Josh McCullough

    FYI, maybe it was different at the time of writing but regarding your warnings: 1) elastic (static) IPs are free as long as you use them (you get one free per EC2 instance); 2) data doesn’t get wiped out when you shutdown an instance, only when you *terminate* (aka delete) an instance – even then, you would have had to elect to have the storage deleted with it.