DEV Community

Cover image for "Step-by-Step Guide: Hosting a Website Using an EC2 Instance on AWS"
Puneet Jena
Puneet Jena

Posted on

"Step-by-Step Guide: Hosting a Website Using an EC2 Instance on AWS"

Certainly! Here are the step-by-step instructions to create an EC2 instance, install Apache server, convert the .pem file to .ppk file, copy files using WinSCP, and access your static website using the public IP:

Create an EC2 Instance:

  1. - Log in to the AWS Management Console.
  2. - Go to the EC2 Dashboard.
  3. - Click on the "Launch Instance" button.
  4. - Choose an Amazon Machine Image (AMI) based on your requirements.
  5. - Select the instance type that suits your needs.
  6. - Configure the instance details and storage.
  7. - Configure security groups to allow inbound HTTP traffic (port 80).
  8. - Review the instance details and launch the instance.
  9. - Select or create a key pair (.pem file) to connect to the instance securely.

Install Apache Server:

1- Connect to your EC2 instance using SSH.
Run the following command to install Apache server:

  • sudo yum install httpd

2-Start and Enable Apache Server:

  • sudo systemctl start httpd
  • sudo systemctl enable httpd

Convert .pem File to .ppk File using PuTTYgen:

  1. - Download and install PuTTYgen (available at https://www.puttygen.com/).
  2. - Launch PuTTYgen and click on "FILE" to load your .pem file.
  3. - Save the private key in .ppk format by clicking on "Save private key".

Copy Files Using WinSCP:

Download and install WinSCP (available at

  1. - https://winscp.net/eng/download.php).
  2. - Launch WinSCP and create a new session.
  3. - Enter your EC2 instance's public IP, username (typically "ec2-user"), and the path to your .ppk file.
  4. - Connect to the instance and navigate to the "/home/ec2-user" directory.

  1. - Copy the static website folders/files from your local machine to the "/home/ec2-user" directory on the EC2 instance.
  2. - Copy Files from /home/ec2-user to /var/www/html:

Already Connectted to your EC2 instance using SSH Now Copy the Files/Folders.

  1. - Run the following command to copy the files from the "/home/ec2-user" directory to the "/var/www/html" directory:
  2. - sudo cp -R /home/ec2-user/* /var/www/html/
  3. - Access Your Static Website:

Open a web browser and enter your EC2 instance's public IP address.
You should be able to view your static website.
Remember to replace "your.pem" with the actual name of your .pem file and "your-public-ip" with the EC2 instance's public IP address.

Top comments (0)