February 18th, 2025
How to Launch a Simple AWS EC2 Server for Your First Web Application
Want to host your first web application on Amazon Web Services? Learn how to set up a basic EC2 instance, configure security, and deploy a simple web server step by step in this beginner-friendly tutorial.
Want to host your first web application on Amazon Web Services? Learn how to set up a basic EC2 instance, configure security, and deploy a simple web server step by step in this beginner-friendly tutorial.
Blog Post
Introduction
Amazon Web Services (AWS) offers a robust, scalable platform for hosting anything from small personal projects to large-scale enterprise applications. This guide will walk you through launching a simple AWS EC2 server—the building block of most AWS infrastructures—so you can get a basic website or app up and running quickly.
Prerequisites
- AWS Account: If you don’t have one, sign up for AWS. New accounts often come with free-tier options that allow you to experiment at minimal or no cost.
- Basic Command Line Knowledge: While not strictly required, familiarity with your operating system’s terminal (macOS/Linux) or Command Prompt (Windows) is helpful.
- SSH Key Pair: You’ll generate this in AWS during the instance launch process if you don’t already have one.
Step 1: Log in to the AWS Management Console
- Navigate to aws.amazon.com and sign in using your credentials.
- From the console home page, search for EC2 or click Services > EC2.
Step 2: Launch a New EC2 Instance
- Click “Launch instances” on the EC2 dashboard.
- Give your instance a descriptive name, such as “MyFirstEC2Server.”
- Under Application and OS Images (Amazon Machine Image), select a Linux-based AMI, such as “Amazon Linux 2 AMI (Free Tier eligible).”
- Choose an instance type that is within the Free Tier if you’re trying to keep costs low (e.g.,
t2.micro
). - Key Pair (login): Either select an existing key pair or create a new one. Download the private key file (
.pem
) and keep it safe. You will use this file to connect via SSH. - For Network Settings, keep the defaults if you’re just experimenting. AWS will automatically create a security group allowing SSH (port 22) and optionally HTTP (port 80) if you enable it.
- Scroll down and click Launch Instance.
Note: It may take a couple of minutes for AWS to provision your server.
Step 3: Configure Security Group for Web Traffic
If you want to run a web server, you need to allow inbound HTTP (port 80) or HTTPS (port 443) traffic.
- In your EC2 dashboard, find the newly launched instance and click on its Security Group.
- Click Edit Inbound Rules.
- Add a rule for HTTP (port 80,
0.0.0.0/0
for anywhere access) or HTTPS (port 443). - Save your changes.
Step 4: Connect to Your EC2 Instance
- In the EC2 console, select your instance and click Connect.
- Switch to the SSH client tab to see instructions.
- Open a terminal (macOS/Linux) or use PuTTY (Windows).
- Navigate to the directory containing your
.pem
file. - Run the SSH command provided by AWS, typically something like:
chmod 400 /path/to/your-key.pem
ssh -i "/path/to/your-key.pem" ec2-user@ec2-xx-xxx-xx-xxx.compute-1.amazonaws.com
- Type yes to confirm the first connection, and you should now be logged into your EC2 server.
Step 5: Update and Install a Web Server
While connected to your server via SSH:
- Update the package list:
- Install Apache (HTTPD) on Amazon Linux:
sudo yum install -y httpd
- Start the Apache service and set it to launch on boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Step 6: Test Your Web Server
- In your browser, go to the Public IPv4 address or Public DNS of your EC2 instance.
- You can find it in the EC2 dashboard under Instances > Description.
- You should see the Apache test page if everything is configured correctly.
Step 7: Customize Your Webpage
- Navigate to the document root directory of your server:
- Create or edit an
index.html
file:
- Add a simple HTML line, for example:
<h1>Hello from AWS EC2!</h1>
1. Save the file (Ctrl + X, then Y, then Enter if using nano
).
2. Refresh your browser. You should now see your custom “Hello from AWS EC2!” message.
Next Steps and Recommendations
- Use Elastic IP: If you want a static IP that won’t change every time you stop/start the instance, allocate an Elastic IP in AWS and associate it with your instance.
- Set Up HTTPS: Use AWS Certificate Manager (ACM) and an ALB (Application Load Balancer) or Let’s Encrypt with Apache to serve your site securely over HTTPS.
- Automation: Consider infrastructure-as-code tools like AWS CloudFormation or Terraform to manage server deployments in a reproducible manner.
- Monitoring: Configure Amazon CloudWatch to track your EC2 instance’s performance and set up alarms for CPU usage, disk space, etc.
Conclusion
Setting up a simple AWS EC2 instance is one of the easiest ways to get started with cloud computing. From creating an account to installing a web server, this process lays a foundation for more complex architectures you might build in the future. AWS offers a vast range of services that integrate seamlessly with EC2, providing everything you need to scale your application as it grows.
This tutorial was written by Patrick Flanagan, a Google Apps Script enthusiast who specializes in custom workflow automations, helping businesses harness the full potential of Google Workspace and more. If you have questions or need assistance with your own App Script projects, reach out to learn more! https://www.univium.com/contact