Building a Web Server on EC2

Due date: Tuesday 14 February 2017, 11:59:00 pm

The goal of this exercise is to familiarize one with:

  • Launching, managing, running EC2 instances
  • Basic system administration of Linux machines

The following instructions will help you, but they are not comprehensive. You should expect to use some intuition, web searching, and trial and error to get everything working.

Create an Amazon Web Services (AWS) account

If you already have an AWS account you can skip this step. You will need a credit card to complete this process.

  • Go to http://aws.amazon.com/ and click the Sign Up button on the top of the page.
  • Follow the steps until you are done.

Sign in to EC2

Creating VPC

  • Go to https://console.aws.amazon.com/vpc/.
  • Click “Your VPCs” on the left, then “Create VPC” and fill in the fields: create vpc
  • Click “Subnets” on the left, then “Create Subnet” and fill in the fields: create subnet
  • Click “Internet Gateways” on the left, then “Create Internet Gateway” and fill in with your VPC name.
  • Then make sure to attach the gateway to the VPC: create igw
  • Click “Route Tables” on the left, then highlight the cs420 row, scroll to the bottom, click the “Routes” tab.
  • Click “Edit”, then “Add Another Rule” so that it looks like this: create routes

Creating Security Group and Key Pair

  • Go to https://console.aws.amazon.com/ec2.
  • Click “Security Groups” on the left under Network and Security, then “Create Security Group”, then edit the Inbound rules to have the following rows: create sgroup
  • Click “Key Pairs” on the left under Network and Security, then “Create Key Pair”. Choose a name (anything you will remember). This will download a “.pem” file with login credentials. You need to keep this file. Put is somewhere that you can find it.
  • change the permissions of the file: e.g., chmod 0600 cs420.pem on your local machine

Launch a micro instance

  1. Select “Instances”, then “Launch Instance”. Check the box on the left menu bar next to “Free tier only”.
  2. Select Ubuntu Server 16.04 LTS (HVM), SSD Volume Type. On the next page, select the first instance listed (t2.micro).
  3. Next: “Configure Instance Details”.
    • Change “Auto-assign Public IP” to Enable: config vpc1
  4. Next: “Add Storage”. These settings are fine.
  5. Next: “Tag Instance”
    • fill in a value field for the name. This is how your instance will appear in the console.
  6. Next: “Configure Security Group”.
    • Choose “Select an existing security group” and choose the cs420 group you created earlier: config vpc2
    • You should see a warning about your security group being open to the world. This is fine for now.
  7. Finally, select “Review and Launch”.
  8. Click Launch instance. You will be prompted for a keypair. Use an existing pair. The one you created earlier.

Log into the instance

  • Go to the ec2 dashboard and select running instances
  • Highlight the instance (radio button)
  • Get the public DNS name (or IP address)
  • Login to the instance using ssh:
    • different instances require different user names, ubuntu instances require ubuntu.
    • e.g., if you instance is ec2-54-84-25-90.compute-1.amazonaws.com and your keypair cs420.pem you would use ssh -i cs420.pem ubuntu@ec2-54-84-25-90.compute-1.amazonaws.com
    • Your .pem file must be visible to ssh. Give a full path or have it in the local directory.

Install a Web server

Everyone should know how to build a web server. Install apache, php, and enable the php module for apache.

sudo apt-get install apache2 php7.0 libapache2-mod-php7.0
sudo a2enmod php7.0
sudo /etc/init.d/apache2 start

Create a file /var/www/html/index.php that contains the following information. You will need to sudo this command, e.g. sudo nano /var/www/html/index.php

<?php phpinfo() ?>

Read the file through a Web browser. Again, get the DNS name.

e.g. http://ec2-54-84-25-90.compute-1.amazonaws.com/index.php

What to turn in

This assignment has two parts. The first is a file generated by the EC2 instance Web server. The second is a PDF writeup. For this assignment (and most future assignments in the course) both the writeup and the associated files/code will be submitted separately via Gradescope. You will need to create a gradescope account if you do not already have one. Visit Gradescope, create an account, and use the entry code M64PYM to link your account to the course.

  1. Project 0 Code: The source of the webpage returned from the index.php page as a file named index.php (index.html or index.htm is fine, too). It should look something like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0057)http://<<YOUR INSTANCE DNS NAME HERE>>.compute-1.amazonaws.com/index.php -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
   ...
   (about 20 lines here)
   ...
</style>
<title>phpinfo()</title><meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE"></head>
   ...

Note that after submission, a grading script will automatically run and compare portions of your file with ours. If everything looks good, you should see a 10/10 in your code grade shortly after submission.

  1. Project 0 Writeup: A PDF document briefly answering the following questions. Make sure to give the unix command line you used to answer the question. (e.g. 0. How long has the system been powered on? Answer: 5 mins. Command: uptime.)

  2. How large is the system’s root drive, mounted on “/”?
  3. How much memory does the system have?
  4. How much memory is being used?
  5. What linux kernel version are you running?
  6. What is the MAC address of the Ethernet card?
  7. What is the last message in the log file where system messages/errors would be found? Where is this file located?

TERMINATE YOUR EC2 INSTANCES