AWS Introduction

Technical Articles
Welcome Page
Goals of this Tutorial
This tutorial will walk through creating an Amazon EC2 instance and putting a simple web server on it.

EC2 is an abbreviation of Elastic Compute Cloud. Compute refers to the compute resources being presented. These resources are generally thought of as servers, however the correct term is EC2 instances. Cloud refers to the fact that EC2 instances are cloud-hosted compute resources. Elastic refers to the fact that an application can be configured to increase or decrease the amount of servers required by an application. 

Sign In
First, go to and click the button marked “Sign in to the Console”.

You must have an AWS account. Note that free accounts are available for one year. If you do not have an account, you can create one by clicking:
Create a new AWS account

You will need:
  • Name
  • Mailing address
  • Company name (if business account)
  • Telephone number
  • Email address
  • Credit card

It will take a few minutes for your account to set up by Amazon. Once you receive an email confirming your account is set up, you can log in and begin this tutorial. Note, as shown above, to log in you go to and click the button marked “Sign in to the Console”.  

Overview of Steps
The tutorial will cover these steps:
  • Log into AWS console (completed, above)
  • Choose a region where we’re going to host our instance
  • Launch the EC2 wizard
  • Select the AMI (Amazon Machine Image, provides the software platform for our instance)
  • ​Select the instance type (hardware capabilities)
  • Configure:
    • Network
    • Storage
    • Key pairs 

​Choose a Region
You can change the location where you instance is hosted in the upper-right. My instance defaulted to Ohio, yours will default to a location relatively close to you. 
Your browser will now display the console you are using. For example mine is:
But, if I change to Oregon, it will change to:

Find EC2
Find “Compute” and “EC2” under “All services. If you don’t see EC2, make sure All Services is expanded. (In other words, make sure the arrow next to “All Services” is point down).

Click on EC2. Then click the large blue “Launch Instance” button.  

Select the AMI
Now select the Amazon Machine Image (AMI).  The AMI is essentially a template. An AMI indicates the operating system, application server, applications and other parts of the software configuration required to launch your instance.

Select: Ubuntu Server 16.04 or 18.04

Ubuntu is a popular Linux distribution. Also popular are Red Hat and distributions based on Red Hat. The instructions for the web server install, below, are for Ubuntu and not the distributions derived from Red Hat.  (Note that 16.04 version will probably be replaced by Ubuntu server 18.04 some time late in 2018).

For your first instance, you can take the defaults in the next screens:
  • Configure Instance Details
  • Add Storage
  • Add Tags 

Add Tags
While it is not critical for a first attempt, you can add a tag to your instance to identify it. 


Configure Security Group
A security group is a set of firewall rules. A default rule for ssh connectivity is created automatically. Another rule should be added for simple web connectivity. Click the “Add Rule” button and select HTTP. The default settings should be sufficient:
Type: HTTP
Protocol: TCP
Port range: 80
Custom:, ::/0

Review the instance settings and then click Launch.

SSH key pair
You must create an ssh key pair and download it to your computer. You can only connect to an EC2 instance by using ssh keys. Make sure you make a note of the name and location where the key is downloaded. Note that you can use this same key pair for future EC2 instances, so you may want to create a name for the key that is not specific to the instance.

Once the instance is created, find the public DNS name for the instance. Use that to connect from Linux, MacOS Terminal or Putty on Windows.

From a UNIX terminal like in Linux or MacOS, the command you use is:
ssh -i ssh_key [email protected]

For example:
ssh -i .ssh/peter_aws.pem [email protected]

Note that the ssh key is often stored in the .ssh directory and that the default user ID on a new AWS EC2 instance is: ec2-user.
Install Web Server
Once terminal connected to your Amazon Ubuntu server instance, you can install the web server software. This software is stored in a repo (officially: software repository).

Periodically, the repository information saved on your server needs to be updated. Preferably, this is done before every update. The repository information lets the Linux OS know what software is available. 

The apt utility is used for this in Ubuntu. The command is:
sudo apt update

The output will look something like:
Hit:1 xenial InRelease
Get:2 xenial-updates InRelease [109 kB]
Get:3 xenial-backports InRelease [107 kB]
[some output removed]
Get:41 xenial-security/multiverse amd64 Packages [3,456 B]
Get:42 xenial-security/multiverse Translation-en [1,744 B]
Fetched 25.3 MB in 4s (5,539 kB/s)             
Reading package lists... Done
Building dependency tree       
Reading state information... Done
38 packages can be upgraded. Run 'apt list --upgradable' to see them.

You can see all the software packages in the repository with this command:
sudo apt list
You can see just the upgradable software packages in the repository with this command:
sudo apt list --upgradable

The software we will install is:
  • Apache web server
  • MySQL database
  • PHP scripting language

This software is often run on Linux. As a result, this combination is sometimes referred to as LAMP for Linux Apache MySQL and PHP. This combination of software, and associated packages, can be installed with this command:
sudo apt install lamp-server^

Be sure to include the ^ at the end of the command (shift-6 on qwerty keyboards). 

When you run this command, a list of software that will be installed is listed. At the end, it displays the amount of disk space that will be used and ask for a confirmation:
After this operation, 183 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

Strike the Y key (for yes).

Note that sudo does not prompt you for a password. Someone who has used sudo elsewhere might be surprised by this. However, as ssh keys were used to log into the AWS instance, a password is not used. The ssh keys are considered safer than passwords. In fact, accounts on AWS instances are not given passwords.

MYSQL Password
During the installation, a password is added for the MySQL database. This password will be needed later.
Install PHP
Then install PHP using this command:
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Check the contents of /var/www/html with this command:
ls /var/www/html
ls -l /var/www/html

The output probably will show this file: index.html

The directory /var/www/html is usually used for the web root directory. The web root is where Apache will look for the files that make up your website. The location of the web root can be changed in the Apache configuration file (/etc/apache2/apache2.conf).

Use one of these commands to display the contents of index.html:
cat /var/www/html/index.html
less /var/www/html/index.html
more /var/www/html/index.html
view /var/www/html/index.html
vi /var/www/html/index.html

If you put the IP address displayed in the instance information in a browser, you should see the contents of index.html. 

Before customizing index.html, it is a good idea to make a copy. Since index.html does not need to have very much content, we will rename it and create a new one. To rename a file in Linux (or UNIX), cd into the web root (/var/www/html) and use the mv (move) command:

cd /var/www/html 
sudo mv index.html index.html.bak