DEV Community

Abinaya Dhanraj
Abinaya Dhanraj

Posted on

CREATING AN EC2 Instance and Running a Web Server

Title: Creating an EC2 Instance and Running a Web Server

In this task, I created a virtual server using Amazon Web Services and hosted a simple web server so I can access it from outside.

I used Amazon EC2 for this.

What is EC2

EC2 stands for Elastic Compute Cloud. It allows us to create virtual machines in the cloud and run applications on them.

Step 1: Launch EC2 instance

First, I logged into AWS console.

Then I went to EC2 service and clicked Launch Instance.

I entered the following details

Instance name as my-server
Selected Amazon Linux image
Instance type as t2.micro
Created a new key pair for login

Step 2: Configure network

I allowed HTTP traffic so that I can access the web server from browser.

In security group settings, I added

Type HTTP
Port 80
Source Anywhere

This step is important, otherwise the site will not open.

Step 3: Launch instance

After configuring everything, I launched the instance.

Then I waited until the instance state became running.

Step 4: Connect to instance

I connected to the instance using SSH.

Using terminal, I used the key pair file to login.

Step 5: Install web server

After connecting, I installed a web server.

Command
sudo yum install httpd -y

Then I started the service

sudo systemctl start httpd

Also enabled it

sudo systemctl enable httpd

Step 6: Add simple webpage

I created a simple HTML file.

Command
echo Hello this is my first server > /var/www/html/index.html

Step 7: Access from browser

Now I copied the public IP of the instance.

In browser, I entered the IP.

The webpage opened and showed my message.

What I understood

EC2 allows us to create servers easily.

Security group controls access like a firewall.

Web server like httpd is used to serve webpages.

Conclusion

By using EC2, I was able to create a server, run a web application, and access it from outside using a public IP. This is the basic idea behind hosting websites in the cloud.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.