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.
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.
Click on EC2 Virtual Servers in the Cloud on the left side of the management console.
Click on the Launch Instance button to create a new EC2 virtual server.
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).
Through Steps 2-5 on the EC2 instance setup, you can click the gray Next button at the bottom right of your browser.
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.
Click the blue button at the bottom right to Review and Launch the instance.
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.
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)
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)).
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.
Once you have the public DNS, you can SSH onto the instance. Go back to your terminal. The command is:
ssh -i website.pem [email protected]
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.
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.
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!
Your website is now up and running with the default success page for newly installed apache2 web server Amazon Web Service instances. Enjoy!