π Launch Your First Amazon EC2 Instance to Host a Web Server
If you're starting your cloud journey with AWS, Amazon EC2 (Elastic Compute Cloud) is one of the first services you'll work with. It allows you to launch virtual machines in the cloud and host applications with complete control over the operating system, networking, and storage.
In this tutorial, you'll learn how to launch an EC2 instance, configure its networking, automatically install an Apache web server using EC2 User Data, and verify that your website is accessible from anywhere on the internet.
By the end of this guide, you'll have your own web server running on AWS. π
π What You'll Learn
- Launch an Amazon EC2 instance
- Configure a Security Group
- Use EC2 User Data to automate server setup
- Deploy an Apache web server
- Verify the deployment
- Clean up AWS resources
ποΈ Architecture
Deployment Flow
Internet
β
βΌ
Security Group
(SSH :22 | HTTP :80)
β
βΌ
Amazon EC2 Instance
(Apache Web Server)
β
βΌ
Static HTML Page
β Prerequisites
Before starting, make sure you have:
- An AWS Account (Free Tier eligible)
- Basic knowledge of the AWS Console
-
An SSH client
- Windows: PowerShell, Windows Terminal, or PuTTY
- macOS/Linux: Terminal
Step 1 β Launch an EC2 Instance
- Open the AWS Management Console.
- Navigate to EC2.
- Click Launch Instance.
- Enter an instance name (for example, demoEC2).
- Choose the Amazon Linux 2 AMI.
- Select t3.micro as the instance type.
- Create or select an existing Key Pair.
- Under Network Settings, configure the Security Group.
Configure Inbound Rules
| Type | Port | Source |
|---|---|---|
| SSH | 22 | My IP (Recommended) |
| HTTP | 80 | 0.0.0.0/0 |
AWS automatically creates a Security Group (for example, launch-wizard-2).
π· Add a screenshot of the Launch Instance page here.
Step 2 β Configure User Data
Instead of manually connecting to the server and installing software, we'll use User Data. The script below runs automatically the first time the EC2 instance boots.
Navigate to:
Advanced Details β User Data
Paste the following script.
#!/bin/bash
# Update packages
yum update -y
# Install Apache
yum install -y httpd
# Start Apache
systemctl start httpd
# Enable Apache after reboot
systemctl enable httpd
# Create sample webpage
echo "<h1>Hello World from EC2 User Data!</h1>" > /var/www/html/index.html
What does this script do?
- Updates installed packages
- Installs Apache HTTP Server
- Starts the Apache service
- Enables Apache to start automatically after every reboot
- Creates a sample HTML page
Once the instance finishes booting, the web server is ready without any manual setup.
π· Add a screenshot of the User Data section here.
Step 3 β Launch the Instance
Click Launch Instance.
Within a minute, the instance state should become Running.
Take note of:
- Public IPv4 Address
- Public DNS
Example:
ec2-xx-xx-xx-xx.ap-south-1.compute.amazonaws.com
π· Add a screenshot of the EC2 Instance Summary here.
Step 4 β Verify the Security Group
Open your instance and navigate to:
Security β Security Groups β Inbound Rules
Verify that the following rules exist.
| Type | Port | Source |
|---|---|---|
| SSH | 22 | Your Public IP |
| HTTP | 80 | 0.0.0.0/0 |
The default outbound rule (Allow All Traffic) is sufficient for this tutorial.
β οΈ Security Best Practice
Avoid exposing SSH (Port 22) to the entire internet in production. Restrict it to your public IP whenever possible.
π· Add a screenshot of the Security Group rules here.
Step 5 β Test the Web Server
Open your browser and visit either:
http://<your-public-ip>
or
http://<your-public-dns>
If everything is configured correctly, you'll see:
Hello World from EC2 User Data!
π· Add a screenshot showing the webpage in your browser.
Step 6 β (Optional) Connect Using SSH
Connect to your EC2 instance:
ssh -i your-key.pem ec2-user@<your-public-ip>
Verify Apache is running.
sudo systemctl status httpd
Expected output:
Active: active (running)
π§Ή Cleanup
To avoid unwanted AWS charges:
- Open the EC2 Console.
- Select your instance.
- Click Instance State.
- Choose Terminate Instance.
π― Conclusion
Congratulations! π
You successfully:
- β Launched an Amazon EC2 instance
- β Configured a Security Group
- β Automated server setup using EC2 User Data
- β Installed and configured Apache
- β Hosted your first web page on AWS
- β Accessed it using a public IP address
Learning EC2 is a major milestone in your AWS journey. From here, you can explore more advanced services such as:
- Elastic Load Balancer (ELB)
- Auto Scaling
- Amazon RDS
- Route 53
- Elastic Beanstalk
- Amazon ECS
- AWS CloudFormation
π¬ Final Thoughts
This is one of the simplest yet most important AWS projects for beginners. It introduces you to compute, networking, security, and automationβall fundamental cloud concepts.
If you found this tutorial helpful, leave a β€οΈ, share it with others learning AWS, and let me know what AWS service you'd like to explore next.
Happy Cloud Learning! βοΈπ
Tags: #aws #cloud #ec2 #devops #beginners

Top comments (0)