Linux Foundations: Installing a Web Server on an EC2 Instance (For Beginners)


If you're just stepping into the world of cloud computing and Linux, setting up a web server on an AWS EC2 instance is an excellent way to gain practical experience. In this short guide, weโll walk you through the process of install and run a web server (Apache or Nginx) on a Linux-based EC2 instance.
โ๏ธStep 1: Start a Linux EC2 Instance
Login to AWS Console
Go to EC2 Dashboard > Launch Instance
Choose an Amazon Machine Image (AMI), e.g., Amazon Linux 2023 or Ubuntu 22.04
Select t2.micro (free tier)
Create or select a key pair
Under Network settings, allow SSH (port 22) and HTTP (port 80)
Launch the instance and wait for it to initialize
๐ Step 2: Connect to Your EC2 Instance
Use the terminal (macOS/Linux) or PuTTY (Windows):
ssh -i my-key.pem ec2-user@<your-ec2-public-ip>
Use
ubuntu@
instead ofec2-user@
if using Ubuntu.
๐ Step 3: Install a Web Server
Option A: Install Apache (httpd)
For Amazon Linux:
sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
For Ubuntu:
sudo apt update
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
Option B: Install Nginx
For Amazon Linux:
sudo amazon-linux-extras enable nginx1
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
For Ubuntu:
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
๐ Step 4: Test It in Your Browser
Open your browser and visit:
http://<your-ec2-public-ip>
You should see the Apache or Nginx welcome page ๐
๐ง Final Thoughts
This is a foundational step in learning Linux and cloud architecture. By launching a simple web server, youโve touched on key concepts like EC2, SSH, Linux package management, and web hosting.
Subscribe to my newsletter
Read articles from Pushkar raj Chouhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
