Table of Contents
In this post we are going to learn about how to turn an EC2 instance into a Web Server. For steps on how to bring up an AWS EC2 instance refer to <Post Launching EC2 Instance>.
As we see below, we already have an EC2 instance up and running. The details of the instance are as below:
- AMI: Linux AMI 2
- Type: t2 micro
- VPC: Default
Related – Default VPC vs Custom VPC in AWS
![Hosting a Web Server on AWS EC2 Instance 1 Hosting a Web Server on AWS EC2 Instance1](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance1.jpg)
Security Group – Web DMZ which allows SSH on port 22 and HTTP on port 80. HTTP needs to be allowed specifically in security group so we have access the Webserver hosted on the EC2 instance.
Related – AWS EC2 Instance Pricing Model
![Hosting a Web Server on AWS EC2 Instance 2 Hosting a Web Server on AWS EC2 Instance2](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance2.jpg)
You can connect to your EC2 instance by clicking on Connect & you shall be able to SSH to the EC2 Instance.
![Hosting a Web Server on AWS EC2 Instance 3 Hosting a Web Server on AWS EC2 Instance3](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance3.jpg)
You will get 3 options to SSH into EC2 Instance.
![Hosting a Web Server on AWS EC2 Instance 4 Hosting a Web Server on AWS EC2 Instance4](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance4.jpg)
We select EC2 Instance Connect to used browser based SSH connection.
![Hosting a Web Server on AWS EC2 Instance 5 Hosting a Web Server on AWS EC2 Instance5](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance5.jpg)
Step-by-Step Guide: Hosting a Web Server on AWS EC2 Instance
Now once you are at the shell of EC2 instance, here are the steps you need to follow to host a Web Server on AWS EC2 Instance.
Step 1
Switch to root ‘sudo –I’ & Look for any OS updates required, run ‘yum update -y’
![Hosting a Web Server on AWS EC2 Instance 6 Hosting a Web Server on AWS EC2 Instance6](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance6.jpg)
Step 2
Install the Apache to turn your EC2 to Web Server. Run ‘yum install httpd -y’
![Hosting a Web Server on AWS EC2 Instance 7 Hosting a Web Server on AWS EC2 Instance7](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance7.jpg)
Step 3
Check now the /var/www/html directory exists and anything we put under this directory would be accessible from the http on port 80.
![Hosting a Web Server on AWS EC2 Instance 8 Hosting a Web Server on AWS EC2 Instance8](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance8.jpg)
Step 4
Let’s create a very basic html file that we will access from web.
Type ‘nano index.html’ to create a new file under www directory
![Hosting a Web Server on AWS EC2 Instance 9 Hosting a Web Server on AWS EC2 Instance9](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance9.jpg)
Click Ctrl + X and save the index.html file.
![Hosting a Web Server on AWS EC2 Instance 10 Hosting a Web Server on AWS EC2 Instance10](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance10.jpg)
Next verify the file is saved under the var/www/html/ directory.
![Hosting a Web Server on AWS EC2 Instance 11 Hosting a Web Server on AWS EC2 Instance11](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance11.jpg)
Step 5
Start the httpd service and verify the same
![Hosting a Web Server on AWS EC2 Instance 12 Hosting a Web Server on AWS EC2 Instance12](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance12.jpg)
Step 6
Go to the browser and input your EC2 instance IP address and you shall be able to see the below output.
![Hosting a Web Server on AWS EC2 Instance 13 Hosting a Web Server on AWS EC2 Instance13](https://ipwithease.com/wp-content/uploads/2020/07/Hosting-a-Web-Server-on-AWS-EC2-Instance13.jpg)
ABOUT THE AUTHOR
![Hosting a Web Server on AWS EC2 Instance 14 facebook 1705333117814 7152685517385936717](https://ipwithease.com/wp-content/uploads/2024/01/facebook_1705333117814_7152685517385936717.jpg)
I am here to share my knowledge and experience in the field of networking with the goal being – “The more you share, the more you learn.”
I am a biotechnologist by qualification and a Network Enthusiast by interest. I developed interest in networking being in the company of a passionate Network Professional, my husband.
I am a strong believer of the fact that “learning is a constant process of discovering yourself.”
– Rashmi Bhardwaj (Author/Editor)