💡Setup Apache Web server in AWS EC2 and Host a Simple Static Website
⭐What is Apache?
✅ Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web.
⭐How to setup Apache in Ec2 Instance (Ubuntu) -
✅ This process is fairly quick and simple so let’s get started…
🔸 First We will need an EC2 Instance. The AMI will be "ubuntu" and t2.micro will be enough for our use case.
🔸 Then Go to the Security Group of the EC2 Instance. Edit the Inbound rule and add HTTP and HTTPS with anywhere IPV4 or My IP.
🔸 Now Connect the Instance with SSH.
🔸 Update your VM.
sudo apt update
🔸 Then Install Apache 2.
sudo apt install apache2
🔸 After Installing Apache2. Always Make sure that Apache is properly Installed by-
apache2 -version
🔸 Start the Apache2 service and check the status.
sudo systemctl start apache2
sudo systemctl status apache2
🔸 Then Go to this directory.
" /etc/apache2/sites-available"
🔸 Then "ls" and got to the
"000-default.conf"
🔸 Edit the Vim File and add this Instead.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html"
ServerName your-domain.com
ServerAlias www.your-domain.com
ErrorLog "/var/log/httpd/your-domain.com-error_log"
CustomLog "/var/log/httpd/your-domain.com-access_log" common
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
🔸Just Change the "ServerName" and "SeverAlias" to your Public IP of EC2 Instance.
🔸 Then Run the command -
sudo a2ensite 000-default.conf
🔸After that Go back to home and Go to this Directory.
"/var/www/html"
🔸 You will find an index.html file edit this according to your liking or you can take the code of any static website from Github and Paste it there. I add my static website code, you can use it to practice.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Static Website</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}
.container {
text-align: center;
background: white;
padding: 2rem;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
}
p {
color: #666;
}
a {
color: #3498db;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to My Website</h1>
<p>This is a simple static website hosted on an Apache web server.</p>
<p>
To learn more about hosting websites on AWS, visit
<a href="https://aws.amazon.com/getting-started/" target="_blank">AWS Getting Started</a>.
</p>
</div>
</body>
</html>
🔸 Now go to your browser and put the public IP of your EC2 instance and your Static website is running through Apache Server.
Well said!