This repository is about launching an Amazon EC2 instance and configuring it as a web server with Apache (httpd).
In this project, we will launch an Amazon EC2 instance using Amazon Linux 2023 and configure it as a web server with Apache (httpd). We will create a customized webpage with a visually appealing design. The setup will be automated using User Data, ensuring that the web server and webpage are configured automatically upon instance startup.
-
Sign in to your AWS Management Console.
-
Navigate to EC2 Dashboard.
-
Click on Launch Instance.
-
Configure the following:
- Name:
Custom-Apache-Web-Server - AMI: Amazon Linux 2023
- Instance Type:
t2.micro(Free Tier eligible) - Key Pair: Proceed without a key pair
- Network Settings:
- Ensure Auto-assign Public IP is enabled
- Create a new security group with the following rules:
- Allow HTTP (80) from Anywhere (
0.0.0.0/0,::/0) - Allow SSH (22) from your IP
- Allow HTTP (80) from Anywhere (
- User Data: Copy and paste the script below (see next section).
- Name:
-
Click Launch Instance.
To automate the installation of Apache and deploy a custom webpage, add the following script to User Data during EC2 instance launch:
#!/bin/bash
# Update package list and install Apache
dnf update -y
dnf install -y httpd
# Start and enable Apache service
systemctl start httpd
systemctl enable httpd
# Set permissions for Apache root directory
chown -R ec2-user:ec2-user /var/www/html
# Create a custom index.html page
cat <<EOF > /var/www/html/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to My Custom Apache Server</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
text-align: center;
padding: 50px;
}
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
display: inline-block;
}
h1 {
color: #333;
}
p {
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to My Custom Apache Web Server!</h1>
<p>Hosted on an Amazon Linux 2023 EC2 Instance.</p>
<p>This page was deployed automatically using AWS User Data.</p>
</div>
</body>
</html>
EOF
# Restart Apache to apply changes
systemctl restart httpd- Go to the EC2 Dashboard and find your instance.
- Copy the Public IPv4 Address.
- Open a web browser and go to
http://<your-public-ip>. - You should see your custom webpage! 🎉
- AWS EC2
- Amazon Linux 2023
- Apache (HTTPD)
- Bash / Shell Scripting
- HTML & CSS
Below is the actual output of the custom Apache web server running on the EC2 instance: