DEV Community

Sharmila devi
Sharmila devi

Posted on

Create a simple EC2 instance and run a webserver and access it from outside.

Creating a Simple EC2 Instance and Running a Web Server

Whenever I started learning AWS, one of the first things I tried was creating an EC2 instance and hosting a simple web server. At first, it felt confusing, but when I did it step by step, it became very easy. Let me explain how I did it in a simple way.

First, I logged into the AWS Management Console. After that, I searched for EC2 and opened the EC2 dashboard. From there, I clicked on Launch Instance to create a new virtual machine.

Next, I gave a name to my instance and selected an Amazon Linux AMI. Then I chose a small instance type like t2.micro because it is free tier eligible.

After that, I created a key pair. This is important because it helps me connect to the instance securely. I downloaded the key file and saved it safely.

Then, I configured the network settings. Here I made an important change — I allowed HTTP (port 80) traffic so that I can access my web server from outside. Without this step, the website will not open in the browser.

Once everything was set, I clicked on Launch Instance. Within a few seconds, my EC2 instance was up and running.

Now I wanted to install a web server. For that, I connected to my instance using SSH. After connecting, I ran some simple commands to install Apache:

sudo yum update -y
sudo yum install httpd -y

Enter fullscreen mode Exit fullscreen mode

Then I started the web server:

sudo systemctl start httpd


Enter fullscreen mode Exit fullscreen mode

To make sure it runs even after restart, I enabled it:

sudo systemctl enable httpd


Enter fullscreen mode Exit fullscreen mode

After that, I created a simple HTML page:

echo "Hello from my EC2 server!" | sudo tee /var/www/html/index.html

Now everything was ready. Finally, I copied the Public IP address of my EC2 instance and pasted it into my browser.

When I pressed enter, I could see my web page showing the message. That moment made me really happy because my server was now accessible from anywhere.

So in simple terms, I created a server in the cloud, installed a web server, and accessed it using a public IP.

This is how I learned to launch an EC2 instance and host a basic web server in AWS.

Top comments (0)