DEV Community

Jarvish John
Jarvish John

Posted on

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

Introduction

In this blog, we will create a simple EC2 instance using Linux, set up a basic web server, and access it from outside using a public IP. This is a fundamental hands-on exercise to understand how cloud servers work.


Prerequisites

  • AWS account
  • Basic Linux command knowledge
  • SSH client (Terminal or Git Bash)

Step 1: Launch an EC2 Instance

  1. Log in to AWS Management Console
  2. Go to EC2 Dashboard
  3. Click Launch Instance

Configuration:

  • Name: simple-linux-server
  • AMI: Amazon Linux
  • Instance Type: t2.micro
  • Key Pair: Create and download

Network settings:

  • Allow SSH (port 22)
  • Allow HTTP (port 80)

Click Launch Instance


Step 2: Connect to the Instance (Linux Terminal)

Navigate to the folder where your key is downloaded and run:

chmod 400 your-key.pem
ssh -i your-key.pem ec2-user@your-public-ip
Enter fullscreen mode Exit fullscreen mode

Step 3: Install Apache Web Server

Update packages and install Apache:

sudo yum update -y
sudo yum install httpd -y
Enter fullscreen mode Exit fullscreen mode

Step 4: Start and Enable Apache

sudo systemctl start httpd
sudo systemctl enable httpd
Enter fullscreen mode Exit fullscreen mode

Check status:

sudo systemctl status httpd
Enter fullscreen mode Exit fullscreen mode

Step 5: Create a Simple Web Page

Replace the default page:

echo "Hello from EC2 Linux Web Server" | sudo tee /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

Step 6: Access from Browser

Open your browser and enter:

http://your-public-ip
Enter fullscreen mode Exit fullscreen mode

You should see:

Hello from EC2 Linux Web Server


Step 7: Security Group Check

If the page does not load, verify:

Type: HTTP
Port: 80
Source: 0.0.0.0/0
Enter fullscreen mode Exit fullscreen mode

Conclusion

You have successfully:

  • Launched a Linux EC2 instance
  • Installed Apache web server
  • Deployed a basic web page
  • Accessed it from the internet

This is the base for deploying real applications on cloud infrastructure


Top comments (0)