Launching Apache Server on EC2
Step 1: Launch an EC2 Instance
- Log in to your AWS Management Console.
- Navigate to the EC2 Dashboard.
- Click on Launch Instance.
- Select an Amazon Machine Image (AMI). For simplicity, choose the latest Amazon Linux 2 AMI.
- Choose an instance type. The t2.micro type is sufficient for a basic web server and is free-tier eligible.
- Click on Next: Configure Instance Details and configure as needed, or accept the default settings.
- Click on Next: Add Storage and configure storage as needed, or accept the default settings.
- Click on Next: Add Tags. Add tags if needed.
- Click on Next: Configure Security Group. Create a new security group with the following rules:
- SSH (port 22) from your IP address.
- HTTP (port 80) from anywhere (0.0.0.0/0).
- Click on Review and Launch.
- Click on Launch and select an existing key pair or create a new one. Make sure to download the key pair if you create a new one.
- Click on Launch Instances.
- Once the instance is running, note the public IP address or public DNS of the instance.
Step 2: Connect to Your EC2 Instance
- Open a terminal (or use an SSH client like PuTTY on Windows).
- Connect to your instance using the key pair you specified. Replace
your-key-file.pem
andyour-instance-public-dns
with your key file and instance's public DNS:ssh -i "your-key-file.pem" ec2-user@your-instance-public-dns
Step 3: Install Apache Server
- Once connected to your instance, update the package index:
sudo apt update
- Install the Apache web server:
sudo apt install httpd -y
- Start the Apache service:
sudo systemctl start httpd
- Enable Apache to start on boot:
sudo systemctl enable httpd
Step 4: Configure Apache Server
- To allow HTTP traffic, add a rule to your security group:
- Go to the EC2 Dashboard in the AWS Management Console.
- Select Security Groups in the left sidebar.
- Select the security group associated with your instance.
- Click on the Inbound Rules tab.
- Click Edit inbound rules.
- Add a rule for HTTP with port range
80
and source0.0.0.0/0
. - Click Save rules.
- Create a simple HTML file to verify Apache is working:
echo "Hello World" | sudo tee /var/www/html/index.html
- In your web browser, go to
http://your-instance-public-dns
. You should see "Hello World".
Summary
You have successfully launched an EC2 instance, installed Apache, and configured it to serve a basic web page. Your Apache server is now running and accessible via the internet.
0 Comments