Installing Apache2 Web Server and Host a Static Website on AWS EC2

Iqbal ShaikhIqbal Shaikh
2 min read

This Blog contains step-by-step instructions for installing an Apache2 web server on an EC2 instance updating, installing, configuring security groups, and accessing via the public IP.

Prerequisites:-

Before we get started, ensure you have the following:

  • An active AWS account

  • (Optional )A basic understanding of EC2, security groups, and static websites.

Steps to Launch and connect to an EC2 Instance.

You need to create an EC2 instance. For Detailed steps Click here

Steps for Hosting a Static Website on AWS EC2.

  1. Log in to the EC2 Linux instance by connecting through AWS default EC2 instance connect.

    1. Use sudo to switch from ubuntu to root for administrative tasks on EC2 Instance to mitigate the risk of unintended alterations affecting system stability or security.

Type sudo su to switch from ubuntu to root; followed by pressing Enter

  1. After sudo-ing to the root user execute the command apt update followed by pressing Enter to install any pending updates

  1. Execute the command apt install apache2 -y followed by pressing Enter to install the apache2 web server on the Ubuntu Instance

  1. Start Apache: Execute the command systemctl start apache2 followed by pressing Enter

  2. Enable Apache to start on boot:

    Execute command systemctl enable apache2 followed by pressing Enter.

    Execute command systemctl status apache2 followed by pressing Enter.

  3. Use this command echo "It works" > /var/www/html/index.html to create the HTML file.

  4. Test Your Website

    Now that everything is set up, open a web browser(chrome) and visit your EC2 instance’s public IP (e.g., http://your-public-ip). If everything is configured correctly, your static website should appear.

    In this Case http://34.227.143.10.

Congratulations on Installing and hosting static website an Apache2 Web Server on EC2! Good job!

How to Create an EC2 instance / Virtual Machine with an Ubuntu AMI on AWS: A Step-by-Step Beginner’s Guide Click here

How to Create Your AWS Free Tier Account 2025

0
Subscribe to my newsletter

Read articles from Iqbal Shaikh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Iqbal Shaikh
Iqbal Shaikh