Setting up an Amazon Web Services EC2 instance for the first time can be a pain in the ass. It’s time for an easy tutorial on how to get a website set up on an AWS EC2 Ubuntu instance.

Step 1:

Go to http://aws.amazon.com. Sign up for an Amazon Web Services account if you don’t already have an account. Sign into your account if you have one.

signin

Sign up for an AWS account or Sign in.

 

Step 2:

Click on EC2 Virtual Servers in the Cloud on the left side of the management console.

ec2

Go to EC2.

 

Step 3:

Click on the Launch Instance button to create a new EC2 virtual server.

Click the Launch Instance blue button.

 

Step 4:

Choose an Amazon Machine Image. You can select from a number of free tier eligible instances, which include a variety of different linux distributions and a windows server. We will be selecting Ubuntu Server 14.04 LTS (HVM).

Select the free tier eligible Ubuntu Server.

 

Step 5:

Through Steps 2-5 on the EC2 instance setup, you can click the gray Next button at the bottom right of your browser.

 

Step 6:

On the Configure Security Group step, you want to Create a new security group for future websites. Input a Security group name in the box and a description in the other box. Add two additional rules. Add rule Type HTTP. Add rule Type Custom TCP Rule. For the Custom TCP rule, input port range 8080 in the box. By adding these two rules, we can see our website online. HTTP is the default website port connection. Port 8080 for the Custom TCP rule is the common alternative port.

Configure Security Group. Add HTTP rule and a Custom TCP rule with port range 8080.

 

Step 7:

Click the blue button at the bottom right to Review and Launch the instance.

 

Step 8:

A Select an existing key pair or create a new key pair prompt box will pop up. Leave the create a new key pair as it is. Write a name for the key pair. Download key pair. This key pair will be used to ssh (get access) to the AWS EC2 instance.

Save the key pair after naming it.

 

Step 9:

For Mac or any Linux distribution, you can open any terminal. For Windows, you must use a program like Cygwin or Putty in order to use SSH. Open up a terminal that can use SSH on your computer. Maneuver to your pem file. ls is to list the contents of the directory. cd is to switch directories/folders.

cd ~ (I change directory to the home folder for my user)
ls (I list the contents of this directory where I saved my pem file)
cygwin

cd – change directory. ls – list contents.

 

Step 10:

To SSH or get access to your Amazon EC2 instance, you must change permissions of the pem (key) file. Amazon likes to secure the instance, so you need specific, secure permissions on the pem (key) file.

ls -l (lists the name and permissions of all files in the directory).
chown :Users website.pem (gives the file ownership to the Users group (for Windows, you have to do this)).
chmod 600 website.pem (allows only the owner of the file to read and write that file (Amazon requires this type of permission for the key to be used)).
permissions

Give the correct permissions to the pem (key) file.

 

Step 11:

Now, you can SSH into the EC2 instance. You first need the public DNS or IP of the EC2 instance. Go back to the EC2 Management Console. Click on Running Instances or Instances on the left sidebar to be brought to the EC2 instance dashboard. By now, your instance state should be running. Click on the instance. At the bottom of your browser, you can see the description of this instance. At the right, you can see a public DNS. Copy the public DNS.

Copy the Public DNS.

 

Step 12:

Once you have the public DNS, you can SSH onto the instance. Go back to your terminal. The command is:

ssh -i website.pem ubuntu@ec2-54-173-189-190.compute-1.amazonaws.com

We SSH onto the instance as the user ubuntu. ubuntu is the default user. The flag -i is to use the key file. Type yes for the fingerprint prompt.

ec2successfullogin

ssh with the key file as ubuntu on the Ubuntu instance.

 

Step 13:

Let’s set up an Apache web server so that our EC2 instance is viewable online. We must first install apache2. For Ubuntu, you type the following command:

sudo apt-get install apache2 (apt-get install is used to install packages on ubuntu. apache2 is a web server that allows our web files to be seen through the browser. sudo is running the command as the super user or basically the administrator.)
Type Y and enter to continue.
installapache2

Install apache2 by using sudo apt-get install apache2.

 

Step 14:

Copy the Public DNS to any web browser and go to the web address. You’ll see that your EC2 instance is now viewable on the web. Hurray!

ec2instanceisup

Copy and paste the Public DNS to a browser, and you can see that the page is up and running with the default success page.

 

Your website is now up and running with the default success page for newly installed apache2 web server Amazon Web Service instances. Enjoy!