Hands-on AWS EC2 | ( Let's Deploy a website on EC2 )
👨🏻💻 Let's Do some real practice on EC2
Overview
- We will be creating an EC2 instance, and then perform following operation on it.
- What we will Learn: AWS EC2, Networking, SSH (cmd, PowerShell can work), Apache server,
Step-1 : Open EC2 Dashboard
- Login to the AWS Management console
- Search EC2 in the search bar and open it.
Step-2 : Create an EC2 Instance
- in the Ec2 dashboard, find the ‘Launch Instance’ option and click on it.
Step-03: Fill out the Asked details and then click on ‘Launch Instance’ to create it.
- Provide any name of your choice:
- In Application and OS Images(AMI):
-
- select any operating system as per requirements.
-
- for this particular article, I am going with 👇🏻 this one…
- In Instance Type: this is the configuration of the virtual machine.
-
- Select t2.micro (default/free)
- Key Pair: required to access the instance from a remote device.
-
- we can create a new key pair or use an existing one.
-
- Create a new one with default options.
-
- key pair should be available on pc for later use. So, download it and keep it safe.
- as we are not familiar with the security group, or traffic. So, leave the rest as default.
- click on ‘Launch instance’
Step-04: SSH into Your Instance
- Go to EC2 instance page
- select instance
- then click on the ‘connect’ option from the menu
- look in SSH Client and coppy the example command from ther
-
- also readout other details there …
- open CLIin the same directory where ‘key pair’ is stored
- then run the example command there and type ‘yes’ for any prompt(see the image)
- after successful implementation, you may notice that the user name is changed to ec2user.
- this means we are successfully logged to our remote EC2 instance/Virtual machine/remote computer. 😎
- Now we can perform multiple tasks on that instance, through this local terminal.
Step-05: Configure EC2 Instance as a Web Server
For this I will be installing an “Apache server”. (well I am doing chatGPT for this part 🤖)
Now execute the following command in your local terminal
- sudo yum update // yum alternative of apt //update all the files
- sudo yum install httpd //
httpd
is the name of the Apache HTTP Server's main executable file - sudo systemctl start httpd //This will run start apache server
- sudo service httpd start // older version // start apache server
- sudo systemctl status httpd // check status of server
- sudo service httpd status // older way // check status of apache server.
- sudo systemctl stop httpd // Don’t run it now 🤖// stop HTTP server
Now our server is live ; let’s first confirm it
- [Note] This might not work for you, to resolve look at the ‘last step’ of this article.
- Go to the instance dashboard
- copy the public IP address and paste it on a new tab.
- So I got this page & you will get it too. 👨🏻🎓 (if not, check the last step 🤖)
Congrats apache server is working.
Step-06: Create and Publish a Sample test.html
File
- sudo nano /var/www/html/test.html //This will create a test.html file and will open the nano editor to put some content there.
- write HTML code there and save it.
- now you are good to go. 😎 site is live 👇🏻
http://your-ec2-public-ip/test.html
⭐⭐⭐
Well, Just deployed the Dictionary app on EC2 server
Last Step: If unable to access the site using a public IP
So let's have a bird's eye view on networking.
This world is trashed with billions of devices. these devices can end up in the wrong place, with the wrong people. Hence there is a lot of concern with the accessibility and safety of the site..
So to handle these cloud platform uses Networking concepts like security group, inbound rule, outbound rule, etc.
- Inbound rule: defines who can come in and access these contents.
> Now In our case, we need to correct this so that everyone can access this instance
- go to the instance page ; find security group ; click on it
- find inbound rule ; click on “edit inbound rules”
- Now add a new rule with the below configuration ; click on ‘save’ button
Now try to access the site using the public address again... 🤖
— End —