How to publish your website on Amazon EC2 Linux Ubuntu server

It will work on other Linux servers as well

So you watched some tutorials (like this one) on how to make a website. You made it and now you want to publish it online. Maybe even on your own Linux server(hosted on your computer, Amazon EC2 or another cloud server). This tutorial is going to show you how to upload your website and point a domain so your website will be "online". The tutorial is basing on Amazon EC2 server with Linux Ubuntu 16,04.

1) Get your server ready

I can recommend Amazon EC2 as it is easy to maintain, idiot-proof and what is most important it has a free tier. Once you sign in to Amazon go to the console and click "Launch Instance" as on image.


Now choose Linux Ubuntu 16,04 LTS. You can choose something else but don't ask me later why it is not working;)
At the end of the deployment, Amazon will also provide you with the pem/ppk file - you will need it later to connect to the server(security feature).

2) Get ftp and SSH clients

FTP client will be used to transfer the files to the server. It is very simple to use so don't get scared. I personally recommend Filezilla which is probably the most popular, Configuration of Filezilla is as easy as clicking File/Sites Manager and pasting server IP address and ppk file from point 1. It took my grandmother 15 minutes to do it (she was 87 that time). Just in case of confusion I made a screenshot and highlighted what and where should be done.


SSH client will be used to connect to the server and change parameters. I recommend Putty (https://www.putty.org/). It is also intuitive to use Putty but just in case here is the step by step tutorial https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html  

3) Upload your website to the server using Filezilla

Connect to the server and simply drag and drop catalogue with your website to /right-click have uploaded folder called "brzezina". There was an error during the first round "Access denied". If it happens to you simply right-click on the "www" folder and set the permissions (777 would do the job).



4) Setup Nginx

What is it about? Well, you will be able to host many websites on just one server. Nginx will be like a roadsign for the users looking for the particular website(by entering a website address in their browsers). You can imagine server as a building and website as a flat in the building. Nginx will show where is the flat in the building so the visitor can get to the place he wants to.

In order to do that you will have to connect to the server using Putty. To install Nginx run those command line by line:

1.. Install nginx:

apt-get install nginx

2. Enable and run the thing:

systemctl start nginx
systemctl enable nginx

Let's set up your website. Create config file by entering this line:

nano etc/nginx/sites-available/yoursite.com

Then paste the following(remember to change domain name and folder)

server {
    listen 80;
    server_name http://biuro-brzezina.pl;
     location / {
 root /var/www/brzezina;
}
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
}

Save it (ctrl+o), than exit (ctrl+x), then copy created file to sites enabled:

ln -s /etc/nginx/sites-available/yoursite.com /etc/nginx/sites-enabled/yoursite.com
And restart Nginx:

service nginx restart
Any problems? There is a simple tutorial on Nginx usage here:
http://nginx.org/en/docs/beginners_guide.html

Remember to change your domain name and folder:)
The website has its own place assigned on your server. Before we set up a domain we need to open port 80 (it is used for websites and it is closed by default). Log in to Amazon console and click on "launch wizard" in the "Security Groups".


Great, now edit inbound rules and add port 80, then save.


5) Set DNS for your domain

To do this you will have to go to the website where you bought your domain and click "manage dns". It is as simple as pasting the IP address of your server. Below I provide a screenshot from godaddy.com. There is step by step tutorial in here: https://gethelp.wildapricot.com/en/articles/546-godaddy-dns-setup



This is it. Now when anyone will enter your domain name in the browser he will be brought to your server, then nginx will take him to the place where your website is stored. I am happy to help you in case of any problems excluding questions "what I have to put in the registration form for Amazon"(believe me or not but I had this kind of questions).