Building a Web Server on EC2

Due date: Friday 15 February 2019

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 as below: create vpc
  • Click “Subnets” on the left, then “Create Subnet” and fill in the fields as below: 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”, then, under the Target tab, select Internet Gateway, and select the igw you set up in the previous step. Set for the destination and “Save” so that it looks like this: create routes

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 t2.micro instance (the only one that’s on the “free tier”).
  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.


Work product

This assignment has two parts. The first is a file generated by the EC2 instance Web server. The second is a PDF writeup.

  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>

Project 0 Questions: You should perform the following actions on your instance and be familiar with the command needed to discover the information. (e.g. 0. How long has the system been powered on? Answer: 5 mins. Command: uptime.) There may be multiple answers to each question.

  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?