apache2 in the cloud: a complete how-to from start to finish using amazon’s ec2

TASK: setup a linux web server running apache2 using Amazon’s recently released free tier of their popular cloud computing service, ec2, which resides on the amazon web services (aws) platform:

LEGAL: this how-to article is to be used as a reference point for your educational needs only. I cannot be held responsible for any misuse and/or monetary charges that you may incur as a result. I strongly urge you to carefully read through the amazon customer service agreement located here as well as here.

MATERIALS REQUIRED:

PART 1 - AMAZON AWS EC2

  1. login to the aws console: https://console.aws.amazon.com/ec2/home

  2. you will be brought to the ec2 dashboard
  3. click on the ‘Launch Instance’ button
  4. we will choose the ‘Basic 32-bit Amazon Linux AMI 1.0’ base (complying with the free tier terms)
  5. change the ‘Instance Type’ from ‘Small’ to ‘Micro’ and then click ‘Continue’
  6. leave the ‘Advanced Instance Options’ as default and click ‘Continue’. confirm that ‘Monitoring’ is UNCHECKED as using this service will incur charges to your aws account
  7. tag your Instance for ease of administration. click ‘Continue’ to proceed
  8. enter a name for your key pair. choose an identifiable name as you will be downloading the key pair file and will require it to connect to your ec2 instance. click on ‘Create & Download your Key Pair’ to continue. save the *.pem file to a secure location
  9. next we configure the firewall. choose a name for your security group and add a description to identify its purpose
  10. we will choose HTTP from the list and click on the ‘Add Rule’ button. you will notice that SSH is already enable by default and we we will leave that as is. click on ‘Continue’ to proceed
  11. before we click ‘Launch’ please review the details and edit as necessary
  12. you will be brought back to the ec2 dashboard. click on ‘Instances’ to see your newly created instance and make note of the ‘Public DNS’ name as we will need this info later on
  13. next we need to connect to our instance by clicking on ‘Connect’ under ‘Instance Management’ and ‘Instance Actions’
  14. a pop-up will appear providing some instructions and information on how to SSH into your newly created ec2 server. we will follow these steps in part 2 of this tutorial below

PART 2: SHH AND APACHE

  1. launch terminal on your mac or putty on your windows based pc (we will use terminal for the purpose of this article)
  2. navigate to where we saved the *.pem file in step #8 of part 1
  3. we need to secure the *.pem file by applying some permissions to it (replace your-key-pair-file with the name of your *.pem file):

    chmod 400 your-key-pair-file.pem

  4. enter the following to code to log into your ec2 server (replace your-key-pair-file with the name of your *.pem file and ec2-xxx.xxx.xxx.xxxx.compute-1.amazonaws.com with the dns name of your ec2 server. this information can be located within the ec2 dashboard by clicking on your ec2 - see step #12 of part 1). please note that although the amazon pop-up suggests logging on via the ‘root’ user, this is not possible as ‘root’ login via ssh is disabled by default. Rather use ‘ec2-user’ instead as shown in the example:

    ssh -i your-key-pair-file.pem ec2-user@ec2-xxx.xxx.xxx.xxxx.compute-1.amazonaws.com

  5. you will now be logged into the ec2 server instance
  6. we need to enable and create a password for the root account:

    sudo passwd root

  7. for some odd reason the amazon linux ami is missing the gcc library that is required to compile our apache2 source. lets download and install gcc (we need to do this as root. click yes to install all the dependencies):

    sudo yum install gcc

  8. create a temporary directory to download apache:

    mkdir apache2

  9. navigate to the newly created ‘apache2’ directory:

    cd apache2

  10. next we will download the latest version and build of apache (you can choose any mirror you’d like):

    wget http://mirror.csclub.uwaterloo.ca/apache//httpd/httpd-2.2.17.tar.gz

  11. we will now extract the downloaded apache2 source file:

    tar xvfz httpd-2.2.17.tar.gz

  12. navigate to the extracted directory:

    cd httpd-2.2.17

  13. now we configure apache2 (we need to do this as root. this process will take a few minutes):

    sudo /.configure

  14. next we compile apache2 (this process will take a few minutes):

    make

  15. and lastly we install apache2 (we need to do this as root):

    sudo make install

  16. we finally have apache2 downloaded, configured, compiled and installed but need to start the service (we need to do this as root):

    sudo /usr/local/apache2/bin/apachectl start

  17. fire up your web browser and populate the address bar with your ec2’s public dns name and hit go. booya! If all went well you should see a page that says ‘It works!

NOTES:

  • you can further configure the apache2 server and also customize the default page. I recommend reading up on the wealth of documentation available at: http://httpd.apache.org/docs/2.2/
  • if you own a domain, you can customize your ec2’s public dns name with a CNAME record
  • why you ask? I am not sure why? boredom? because I can? its there? free?
  • what next you ask? BIND or sendmail or postfix
  • please leave your questions and feedback in the comments below

SOURCES:

  1. caxinas reblogged this from misoverstood
  2. misoverstood posted this
Short URL for this post: http://tmblr.co/ZfDSZy1Oj90Y
blog comments powered by Disqus