How to setup a Ubuntu server using AWS
If you are looking to build a website you will need web hosting, i.e. a server where you host your files (code). In this article I will teach you how to get a Ubuntu 20.x server up and running using AWS. For transparency, this article is not sponsored. I simply use AWS myself and enjoy the provided services.
1. Sign up for an AWS account
Firstly, we will need an AWS account (this is free!). Head over to aws, register a new account and provide the information required by Amazon. Already have an account? Let’s continue.
2. Head over to EC2
Head over to the search bar at the top and type “ec2.” Click the top search result that says: “EC2 — Virtual Servers in the Cloud”, sounds like what we are looking for, right?
3. Pick geographic location
Now that we have navigated to EC2 we have the option to change the geographic location where we wish to deploy our server. Latency is the primary factor you should consider when deciding the location, more specifically your users’. If you live in the US, but most of your traffic is from central Europe, Frankfurt (Germany) might be a better option than Ohio.
To switch, just head over to the top right corner of the navbar (see picture), activate the dropdown and change to the region of choice. It is important that we do this before setup, since changing the location of the server is more difficult afterwards.
4. Beginning setup
Let’s begin initializing! On the home screen of EC2 you should be able to see a jumbotron labeled “Launch instance” with an orange button of the same name. Open the dropdown, and click (probably) the only option: “Launch instance”.
5. Choosing distribution
Now, assuming you are only reading this article with the interest of starting a Ubuntu server, we are going to navigate to this distribution. In the list of distributions, find “Ubuntu Server 20.04 LTS (HVM), SSD Volume Type”. If it is not visible immediately, you may need to use the search function. Searching for “Ubuntu” should be sufficient. Before selecting, make sure 64-bit (x86) is selected on the right hand side, right below the “select”-button. Make sure you find the one identical to the one below, and click “select”:
6. Choose Instance Type
Assuming you also like free stuff, we are going to choose the “t3.micro” instance type. This allows us to host our server for free, with a few limitations of course. Personally, I have hosted two projects starting off at the t3.micro. Both were websites, where I only noticed performance decline whilst hosting more than 100 consecutive users. Therefore, I would begin with the t3.micro instance, and later upgrade if needed. This is easy to do, contrary to changing geographic location. Thus, select “t3.micro” and click “Next: Configure Instance Details”:
7. Add storage
You should now have reached the “configure instance details.” We will not need to change anything here, just click “Next: Add Storage.” Free tier allows up to 30gb of storage, consequently we are going to change the Size (currently 8GB) to 30GB. When that is changed, click “Next: Add tags” and then “Next: Configure Security Group.”
8. Configure Security Group
By default, only SSH is configured. We want to add HTTP and HTTPS, which can be done by clicking “Add Rule”. A new row should be added to your table, with a dropdown on the left. Navigate to “HTTP” and select it. The “Port range” should automatically be set to 80. Now, do this again with the only difference being selecting “HTTPS.” Instead, the port 443 should be selected by default, without any further input required by you. When done, you should have something like this:
Further customization (optional)
For security reasons, a rational option is to change the SSH row’s “Source” to “my IP”. This will hinder outside IP:s to connect to your instance via SSH. Furthermore, you might want to provide your security group with a name. Change “launch-wizard-2” to something of your liking, preferably something reminding you that it is a security group. Add a description if you feel like it.
9. Download Key Pair
Almost done! Just click “Review and Launch” and then “Launch” in the bottom right hand corner. You should be prompted by a model asking about key pairs. Select “Create a new key pair” in the dropdown, and name it. When done, click “Download Key Pair” and store it somewhere safe on your computer (maybe not the Downloads folder, to avoid deleting it by accident). When downloaded, click “Launch instances.”
10. Connect to instance
All set! The last thing to do is to connect to the instance. If you are using windows, I sadly have to refer you to this AWS article, since I don’t have an article on it yet. However, if you are using MacOS follow the steps below:
Change permissions of key file
When using SSH to connect, too “open” permissions of the key file are not allowed. Therefore, open terminal and write the following:
sudo chmod 400 ~/Desktop/my-website-key.pem
The path depends on where you saved your key. If you saved it in Downloads, ~/Downloads/my-website-key.pem is the correct path. Additionally, change the name according to your own- naming of the file as of step (9). More general:
sudo chmod 400 ~/"path to keyfile"/"name of keyfile".pem
When prompted for your password, enter it.
The final command requires our “Public IPv4 DNS” from our instance. Head back to AWS, click “Instances” — either from the left sidebar, or from the “Resources” jumbotron — and click the instance ID of the instance we just created. You should be able to see the “Public IPv4 DNS”, it should look something like this:
To connect, simply type the following in your terminal:
ssh -i ~/Desktop/my-website-key.pem ubuntu@Ec2–14–21–32–453.eu-north-1.compute.amazonaws.com
As per usual, change the path to the one you used to change the permissions of your key file (it is the same). In addition, change the address to the right of “ubuntu@” to your own. The general command is:
Ssh -i “path to key file” ubuntu@”Your Public IPv4 DNS”
Now, this article only serves to help you start up the server. A following article will help you deploy your website.
As per usual, if you have any questions, leave a comment. I will do my very best to help you!