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

  1. Login to AWS Console

  2. Go to EC2 Dashboard > Launch Instance

  3. Choose an Amazon Machine Image (AMI), e.g., Amazon Linux 2023 or Ubuntu 22.04

  4. Select t2.micro (free tier)

  5. Create or select a key pair

  6. Under Network settings, allow SSH (port 22) and HTTP (port 80)

  7. 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 of ec2-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.

0
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

Pushkar raj Chouhan
Pushkar raj Chouhan