RSS
people

My Experiments with AWS – 3 : lamp server, Elastic IP, DNS for ec2

Now that we can connect to the ec2 instance – we want to setup a basic website. I use ubuntu AMI – so, following instructions are for ubuntu. Similar instructions for other platforms can be ported as well.

Installing LAMP Server

# install Apache , PHP and MySql as a package
sudo tasksel install lamp-server
# we may want to enable some of the apache modules
# without rewrite = rewriting URLs will not work
sudo a2enmod rewrite
# headers and expires module will help in performance
sudo a2enmod headers
sudo a2enmod expires

Elastic IP

We have already seen the use of public DNS while connecting to an ec2 instance. One very important point to note here: These public/private DNS will change on reboot. So, after a reboot you can not connect using the same Public DNS as you used to earlier. You will have to check the public name once again and use the newer name to connect. Because of the dynamic nature of the instance public DNS, it is not possible to setup a CNAME entry for domain name directly because after every reboot – name will change and as we all know DNS propagation takes time, which will result in downtime.

Here, elastic IP comes to our rescue. AWS provides this mechanism using which we can ensure that the public IP of an instance is same even after reboot. (You can think of it as assigning a static IP to a machine.) Elastic IP is more powerful because you can simply attach this IP to any other instance later – which means that you can shift machines without worrying about DNS propogation.

So, how do we do it?

  1. Login to aws console and go to ec2 tab. Select the appropriate region.
  2. Click on “Elastic IPs”  under “Networking and Security” heading on the sidebar.
  3. Click on “Allocate New Address”. This will allocate a new IP address. Please note that by default this IP is NOT attached to any machine. Amazon charges some money for un-attached IPs and there is no charge if  the IP is attached with an instance.
  4. After the address is allocated, click on it to select it.
  5. Click on “Associate Address” at the top bar. This will open a popup with an option to select the ec2 instance.
  6. Select the instance you want to associate this IP with.
Refer the screenshot below. Now, whenever you want to connect to this instance – you can either use the public DNS name as described earlier or this elastic IP.

DNS

Now setting up a DNS for a domain is dead simple, as we already have an IP attached to the machine. Let’s say you own a domain name example.com. To host this domain on aws, do the following:

  • Get an ec2 instance, connect to it, install lamp server and attach an elastic IP with the instance. (as mentioned above) Let’s say the IP is XXX.XX.XX.XX
  •  Go to your domain registrar and open the DNS settings page.
  • Add an “A” entry for example.com. with value XXX.XX.XX.XX
  • Wait for some time – let the DNS propagate.
Now your domain example.com is pointing to the ec2 instance and if the instance knows how to handle the http requests for that domain – you are all set.

One Response to “My Experiments with AWS – 3 : lamp server, Elastic IP, DNS for ec2”

  1. AWS Fan Says:

    How do you setup FTP on AWS? I really want to start hosting sites from AWS using a system like cPanel would this be a good idea? Can you recommend any free cPanel type interfaces?
    Thanks for the great AWS posts..

    [Reply]

Leave a Reply