DEV Community

Manoj Kumar
Manoj Kumar

Posted on

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

☁️ Launching an EC2 Instance and Hosting a Web Server (AWS Beginner Guide)

Hi everyone 👋

Today I tried something interesting in AWS —

I created an EC2 instance, installed a web server, and accessed it from my browser 🌐

Let me walk you through the steps in a simple way 👍


📌 What is EC2?

EC2 (Elastic Compute Cloud) is a service provided by AWS that allows you to create a virtual machine in the cloud.

👉 You can use it like your own computer:

  • Install software
  • Run applications
  • Host websites

🚀 Step-by-Step Process


🔹 Step 1: Login to AWS Console

  • Go to AWS Console
  • Search for EC2
  • Click Launch Instance

🔹 Step 2: Configure Instance

Choose the following:

  • Name: MyWebServer
  • AMI: Amazon Linux
  • Instance Type: t2.micro (Free Tier)

🔹 Step 3: Create Key Pair

  • Create a new key pair
  • Download .pem file 👉 This is used to securely connect to your instance

🔹 Step 4: Configure Security Group

Allow these:

  • SSH (Port 22) → for login
  • HTTP (Port 80) → for web access

👉 Very important step!


🔹 Step 5: Launch Instance

Click Launch Instance

Your EC2 server is now running 🎉


🔹 Step 6: Connect to EC2

Use SSH:

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

🔹 Step 7: Install Web Server

Install Apache:

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

Start server:

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

🔹 Step 8: Create a Simple Web Page

echo "<h1>Hello from EC2 🚀</h1>" | sudo tee /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

🔹 Step 9: Access from Browser

Open browser and enter:

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

👉 You will see your webpage 🎉


🔁 Simple Flow

User → Browser → Public IP → EC2 Instance → Apache → Web Page
Enter fullscreen mode Exit fullscreen mode

🧠 Real-Life Understanding

Think of EC2 like renting a computer in AWS:

  • You install software
  • You run a server
  • Others can access it via internet

⚡ Important Points

✔ EC2 gives full control

✔ Security groups act like firewall

✔ Public IP is used for access

✔ Apache serves the webpage


🔐 Security Tip

  • Never share your .pem file
  • Restrict SSH access if needed
  • Use HTTPS for production

✅ Conclusion

In this task, we:

  • Created an EC2 instance
  • Installed a web server
  • Hosted a webpage
  • Accessed it from outside

This is the basic foundation of cloud hosting 🚀


Thanks for reading 😊

Top comments (0)