Building a Web Server on EC2

Due date: Thursday 8 February 2018, 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 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
  • 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”, then “Attach to VPC” 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” and “Save” so that it looks like this: create routes Note: Target will automatically pop out if you have done previous steps correctly. Target number will not match the one in the picture.)

Creating Security Group and Key Pair

  • Go to
  • 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: “Add Tags”
    • 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 and your keypair cs420.pem you would use ssh -i cs420.pem
    • 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

sudo may give you a warning that it cannot resolve the host name. This may be safely ignored.

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.


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 M2RWXZ 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>> -->
<html xmlns=""><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
   (about 20 lines here)
<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.

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.)

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