DEV Community

Cover image for Documentation for Setting Up a Web Server on EC2 (Ubuntu)
Victor Okonkwo
Victor Okonkwo

Posted on

Documentation for Setting Up a Web Server on EC2 (Ubuntu)

Documentation for Setting Up a Web Server on EC2 (Ubuntu)

Step 1: Create an EC2 Instance

  • Go to the AWS Management Console and navigate to EC2.
  • Click Launch Instance.
  • Configure the instance:
    • AMI: Select Ubuntu.
    • Instance Type: Choose an appropriate size (e.g., t2.micro for free tier).
    • Key Pair: Select or create a key pair.
    • Security Groups: Allow inbound rules for HTTP (port 80) and SSH (port 22).
  • Launch the instance.

Step 2: Download the Key Pair

  • When creating a key pair, download the .pem file to a secure location on your local machine.
    • Note: This file is crucial for accessing your EC2 instance.

Step 3: Copy the Key Pair to WSL

  • Open your WSL terminal on your local machine.
  • Copy the .pem file to your WSL home directory: (You manually copied the file in File Explorer and pasted it in a new folder you created for SSH keys)
  cp /path/to/key-pair.pem ~/key-pair.pem
Enter fullscreen mode Exit fullscreen mode

Step 4: Set Key Pair Permissions

  • Set the correct permissions for the key pair:
  chmod 400 ~/key-pair.pem
Enter fullscreen mode Exit fullscreen mode

Step 5: SSH Into Your EC2 Instance

  • Use the public IP address of your EC2 instance to connect:
  ssh -i ~/key-pair.pem ubuntu@<public-ip-address>
Enter fullscreen mode Exit fullscreen mode
  • If prompted, type yes to confirm the connection.

Step 6: Update the System

  • Update the package index and upgrade installed packages:
  sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Step 7: Install Apache

  • Install the Apache HTTP server:
  sudo apt install apache2 -y
Enter fullscreen mode Exit fullscreen mode
  • Enable and start Apache:
  sudo systemctl enable apache2
  sudo systemctl start apache2
Enter fullscreen mode Exit fullscreen mode
  • Verify Apache is running:
  sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

Step 8: Configure Firewall

  • Allow Apache through the firewall:
  sudo ufw allow 'Apache'
  sudo ufw enable
Enter fullscreen mode Exit fullscreen mode
  • Verify the status of the firewall:
  sudo ufw status
Enter fullscreen mode Exit fullscreen mode

Step 9: Test the Web Server

  • Open a browser and enter your instance’s public IP address.
  • You should see the Apache default page.

Troubleshooting Tips

Issue 1: Unable to access the Apache page

  • Check if Apache is running:
  sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode
  • Verify security group rules in AWS allow traffic on port 80.
  • Confirm ufw is allowing HTTP traffic:
  sudo ufw status
Enter fullscreen mode Exit fullscreen mode

Issue 2: SSH connection fails

  • Ensure the correct IP address and .pem file are used.
  • Check that your IP is whitelisted in the EC2 instance's security group.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay