Launching Apache Server on EC2

Launching Apache Server on EC2

Launching Apache Server on EC2


Step 1: Launch an EC2 Instance

  1. Log in to your AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. Click on Launch Instance.
  4. Select an Amazon Machine Image (AMI). For simplicity, choose the latest Amazon Linux 2 AMI.
  5. Choose an instance type. The t2.micro type is sufficient for a basic web server and is free-tier eligible.
  6. Click on Next: Configure Instance Details and configure as needed, or accept the default settings.
  7. Click on Next: Add Storage and configure storage as needed, or accept the default settings.
  8. Click on Next: Add Tags. Add tags if needed.
  9. 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).
  10. Click on Review and Launch.
  11. 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.
  12. Click on Launch Instances.
  13. Once the instance is running, note the public IP address or public DNS of the instance.

Step 2: Connect to Your EC2 Instance

  1. Open a terminal (or use an SSH client like PuTTY on Windows).
  2. Connect to your instance using the key pair you specified. Replace your-key-file.pem and your-instance-public-dns with your key file and instance's public DNS:
    ssh -i "your-key-file.pem" ec2-user@your-instance-public-dns
          ssh -i "ubuntu.pem" ubuntu@ec2-13-57-xx-xx.us-west-1.compute.amazonaws.com 

Step 3: Install Apache Server

  1. Once connected to your instance, update the package index:
    sudo apt update  
  2. Install the Apache web server:
    sudo apt install httpd -y
  3. Start the Apache service:
    sudo systemctl start httpd
  4. Enable Apache to start on boot:
    sudo systemctl enable httpd

Step 4: Configure Apache Server

  1. To allow HTTP traffic, add a rule to your security group:
    1. Go to the EC2 Dashboard in the AWS Management Console.
    2. Select Security Groups in the left sidebar.
    3. Select the security group associated with your instance.
    4. Click on the Inbound Rules tab.
    5. Click Edit inbound rules.
    6. Add a rule for HTTP with port range 80 and source 0.0.0.0/0.
    7. Click Save rules.
  2. Create a simple HTML file to verify Apache is working:
    echo "Hello World" | sudo tee /var/www/html/index.html
  3. 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.

Post a Comment

0 Comments