Deploying an Apache Web Server on EC2

Ever wanted to host your own website or web application but felt intimidated by the complexities of server management? You're in the right place! In this step-by-step guide, we'll demystify the process of deploying a powerful and widely-used web server – Apache – on Amazon Web Services' (AWS) scalable and reliable Elastic Compute Cloud (EC2). Whether you're a budding developer, a small business owner, or simply curious about web hosting, this post will equip you with the knowledge to get your web presence up and running in the cloud. Let's dive in and harness the power of EC2 and Apache together!
Login to aws console
Find ec2 or search in searchbar, click ec2
Click on instances
You will get list like this, click on launch instances
Provie the required information
Its always recommended to use free tier
Create a new key pair for newly generated ec2 instance, to login using ssh
Security group is important, it makes sure the ec2 instance
1 . Should be available to outside or not, if available then which port should be available
2. From which ip range ec2 instance can be accessed
3. Should this instance to able to communicate to outsideAfter doing security works, our final work is to include user-data
1. It helps us to pre install or pre configure our instance while instance is getting created#!/bin/bash # Update package list and install Apache apt update -y apt install -y apache2 # Start and enable Apache service systemctl start apache2 systemctl enable apache2 # Set permissions for Apache root directory chown -R www-data:www-data /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 Ubuntu 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 apache2
Provide above code, so instance can install and run apache server while getting created'
Upon successful ec2 instance, you will find a message like this. Click on instance id
After redirecting to ec2 instances list, click or select the instance that you have created. You will find more options based on selection
Copy public ip and paste in your browser
Congrats, you have successfully installed apache and it works fine
N:B: Please wait for ec2 instance to be running. Always remember to destroy / terminate your instances, if you don’t want any surprise billing
Subscribe to my newsletter
Read articles from Tonmoy Chiran directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
