How to Launch EC2 Instance and Set Up Web Server: Complete Step by Step Guide
By Braincuber Team
Published on March 14, 2026
Launching your own web server in the cloud is easier than you might think. With AWS EC2 instances and Apache HTTPD, you can have a fully functional web server running in minutes. This complete step by step guide will walk you through everything from launching your first EC2 instance to hosting your custom web page.
What You'll Learn:
- Understanding EC2 instances and HTTPD web servers
- Creating and configuring EC2 instances with proper security settings
- Connecting to EC2 instances using SSH and key pairs
- Installing and configuring Apache HTTPD web server
- Hosting custom web pages and managing server content
- Best practices for EC2 security and server management
What Is EC2?
Think of EC2 (Elastic Compute Cloud) as a hotel room in the cloud. Instead of booking a physical server to store your website, you're renting one from Amazon's magical cloud infrastructure. This room (or instance) comes with all the amenities you need to host a website. Today, we'll install HTTPD (a web server software) in our "room" to make our website live.
What is HTTPD?
HTTPD stands for Hypertext Transfer Protocol Daemon. Let's break that down:
Hypertext Transfer Protocol (HTTP)
This is the standard protocol used on the web. When you type a URL into your browser or click a link, you're using HTTP to tell the server, "Hey, send me this web page!"
Daemon (D)
A daemon is just a fancy term for a background process that runs continuously on a server. The daemon responds to requests from web browsers and sends back appropriate content.
HTTPD vs. Apache2
Depending on your Linux distribution, you may encounter different names for the same software. On RPM-based distributions (Red Hat, CentOS, Fedora), it's called httpd. On Debian-based distributions (Ubuntu, Debian), it's referred to as apache2.
Step 1: Launch Your EC2 Instance
First things first, let's launch our EC2 instance. You'll need an AWS account—signing up is free, and AWS offers a free tier, so this won't cost you a dime for small-scale experiments.
Access AWS Management Console
Head over to AWS Management Console and log in. From the search bar, type "EC2" and click on EC2 Dashboard. Create a new instance by clicking on the orange Launch Instance button.
Choose Amazon Machine Image (AMI)
Select the Amazon Linux AMI, which is free-tier eligible and super reliable. Don't forget to give your instance a unique name! Adding a "Name" tag helps you keep track of multiple instances.
Select Instance Type
The t2.micro is your best buddy here again, free-tier eligible and perfect for our needs. Remember the default username for Amazon Linux is ec2-user.
Create Key Pair for SSH Access
If you already have a .pem file, choose it from the dropdown. If not, create a new key pair and download the .pem file safely. This file acts like the secret key to your cloud "hotel room."
Configure Security Group
Set up HTTP rule on port 80 for web visitors and enable SSH on port 22 with restricted IPs. Security groups are like virtual firewalls controlling traffic in and out of your instance.
Launch Instance
Click the Launch Instance button and wait a minute or two for your instance to come online. You've just launched your very own server in the cloud!
Step 2: Connect to Your EC2 Instance
To connect, we'll use the .pem file (key pair) we created earlier. If you're on a Mac or Linux machine, this is super simple with SSH. For Windows folks, I recommend using MobaXterm—it's a user-friendly terminal with SSH built-in.
ssh -i "your-key.pem" ec2-user@your-ec2-public-ip
Replace "your-key.pem" with the name of your key pair and "your-ec2-public-ip" with the public IP of your instance (you can find this in the EC2 dashboard). If you've connected successfully, congratulations! You're inside your cloud server.
Step 3: Install and Start HTTPD (Apache Web Server)
Alright, time to install our web server software (HTTPD)! We'll be using Apache, one of the most popular web servers around. Don't worry, you don't need a degree in IT to get this working.
Update Your Server
It's always good practice to make sure your server is up to date. Run: sudo dnf update -y
Install HTTPD
Next, we'll install HTTPD (Apache): sudo dnf install httpd -y
Start HTTPD Service
Run this command to get your server running: sudo systemctl start httpd
Enable HTTPD on Boot
Enable it to start on boot: sudo systemctl enable httpd. This ensures your web server comes back automatically after reboots.
Time to test it out! Open your browser and type in your instance's public IP. If you see the Apache test page, give yourself a high-five. You've just launched a web server!
Step 4: Host Your Custom Web Page
Now, let's get creative! Instead of the default web server message, let's host your very own custom web page in just one step. This will allow you to display a unique message on your site in no time.
echo "Welcome to Cloud! You're now hosting your own custom web server using AWS EC2 and Apache!" > /var/www/html/index.html
What This Command Does
The echo command outputs your custom message, the > symbol redirects this output to a file, and /var/www/html/index.html is the path to your web server's homepage file.
View Your Custom Page
Find your EC2 instance's public IP address, open your browser, enter that IP, refresh the page, and boom! Your custom message is live on your site.
EC2 Security Best Practices
When running web servers in the cloud, security should be your top priority. Here are essential security practices to follow:
| Security Practice | Why It Matters | Implementation |
|---|---|---|
| Restrict SSH Access | Prevents unauthorized server access | Use specific IP ranges in security groups |
| Regular Updates | Protects against vulnerabilities | Run sudo dnf update -y regularly |
| Use Key Pairs | Secure authentication method | Never share .pem files, store them securely |
| Monitor Logs | Detect suspicious activity | Check Apache and system logs regularly |
Frequently Asked Questions
What's the difference between httpd and apache2?
They're the same Apache web server software with different names based on Linux distribution. On RPM-based systems (Red Hat, CentOS, Fedora), it's called httpd. On Debian-based systems (Ubuntu, Debian), it's called apache2.
How much does it cost to run an EC2 instance?
AWS offers a free tier that includes 750 hours per month of t2.micro instances for the first 12 months. After that, t2.micro instances cost about $0.0116 per hour, or roughly $8.50 per month if running continuously.
Can I connect to EC2 from Windows?
Yes! While Mac and Linux have built-in SSH, Windows users can use tools like PuTTY, MobaXterm, or Windows Terminal (Windows 10/11) to connect to EC2 instances using SSH.
What happens if I lose my .pem key file?
If you lose your .pem key file, you won't be able to access your EC2 instance. You'll need to create a new instance or use AWS Systems Manager to create a new key pair and associate it with your instance (if you have the necessary IAM permissions).
Where are web files stored on the server?
For Apache HTTPD, the default web root directory is /var/www/html/. Any files placed in this directory will be served by the web server. The index.html file is the default homepage.
Ready to Launch Your Cloud Server?
Our cloud infrastructure experts can help you set up secure, scalable web servers on AWS with proper security configurations and best practices.
