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 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
- Go to http://aws.amazon.com/console/ and click “Sign In to the AWS Console” in the box on the right. Complete sign in.
- From https://console.aws.amazon.com/console/home?region=us-east-1 Select EC2 at the upper left, under “Compute”.
- In the upper right hand corner, make sure that your availability zone (next to your name) is “N. Virginia”
- Go to https://console.aws.amazon.com/vpc/.
- Click “Your VPCs” on the left, then “Create VPC” and fill in the fields:
- Click “Subnets” on the left, then “Create Subnet” and fill in the fields:
- 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:
- 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: 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 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:
- 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.pemon your local machine
Launch a micro instance
- Select “Instances”, then “Launch Instance”. Check the box on the left menu bar next to “Free tier only”.
- Select Ubuntu Server 16.04 LTS (HVM), SSD Volume Type. On the next page, select the first instance listed (t2.micro).
- Next: “Configure Instance Details”.
- Change “Auto-assign Public IP” to Enable:
- Next: “Add Storage”. These settings are fine.
- Next: “Add Tags”
- fill in a value field for the name. This is how your instance will appear in the console.
- Next: “Configure Security Group”.
- Choose “Select an existing security group” and choose the cs420 group you created earlier:
- You should see a warning about your security group being open to the world. This is fine for now.
- Finally, select “Review and Launch”.
- 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 firstname.lastname@example.org
- 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.
- Project 0 Code: The source of the webpage returned from the index.php page as a file named
index.htmis 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.
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.)
- How large is the system’s root drive, mounted on “/”?
- How much memory does the system have?
- How much memory is being used?
- What linux kernel version are you running?
- What is the MAC address of the Ethernet card?
- What is the last message in the log file where system messages/errors would be found? Where is this file located?