Guide to Deploying a Static Website on AWS EC2 Using Apache

Step-by-Step Guide

Step 1: Launch an EC2 Instance

  • Log in to AWS Management Console:
  • Navigate to the EC2 Dashboard.
  • Launch a New Instance:
  • Click on "Launch Instance".
  • Choose an Amazon Machine Image (AMI). Select the Ubuntu Server AMI (Ubuntu 20.04 LTS recommended).
  • Choose an Instance Type (e.g., t2.micro for free tier eligibility).
  • Configure Instance:
  • Select an existing key pair or create a new one. Download the key pair (.pem file).
  • Configure Security Group:
  • Create a new security group.
  • Add a rule to allow SSH (port 22) and HTTP (port 80) from anywhere (0.0.0.0/0).
  • Review your settings and click "Launch".

Step 2: Connect to Your EC2 Instance

  • Open a Terminal/PowerShell:
  • Navigate to the directory containing your .pem file.
  • Connect to the Instance:
  •       ssh -i "path/to/your-key.pem" ubuntu@your-ec2-instance-public-ip
    

    Step 3: Install and Configure Apache

    • Update the Package Lists:
    •         sudo apt update
      
    • Install Apache:
    •         sudo apt install apache2 -y
      
    • Check Apache Status:
    •         sudo systemctl status apache2
      
    • Apache should be active (running).

    Step 4: Deploy Your Static Website

    • Upload Your Website Files:
    • open another Terminal; copy your website files to the server.
    •         scp -i "path/to/your-key.pem" -r path/to/your-website/* ubuntu@your-ec2-instance-public-ip:/tmp/
      
    • Move Files to the Web Root:
    • return to the terminal already connected to your Ec2 server and move the files to the Apache web root
    •         sudo mv /tmp/* /var/www/html/
      
    • Verify Deployment:
    • Open your web browser and paste your instance's public IP address (e.g., http://54.208.104.210/ ).