"Step-by-Step Guide: Hosting a Website Using an EC2 Instance on AWS"
Published: 2023-07-12 11:21:27

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:**
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfyyt6zylo3waenanbdp.png)

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:
     

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4olb98lx5kuzp71uvri9.png)
 - sudo yum install httpd

 2-Start and Enable Apache Server:
     
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/np0y9onv5f311wi0h7ko.png)

 - sudo systemctl start httpd
 - sudo systemctl enable httpd

**Convert .pem File to .ppk File using PuTTYgen:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mszlbzk5ulia0225n56p.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l31in27etrglj6lwuhb7.png)
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 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0m4yw33zhr5if0s8f7y.png)
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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9rrqtr9qck6imzn8m1o.png)
5. - Copy the static website folders/files from your local machine to the "/home/ec2-user" directory on the EC2 instance.
6. - Copy Files from /home/ec2-user to /var/www/html:

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xe7hpj4h1az7c8pb0lfg.png)

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:



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9kcjs6ndz01m34e0f5n.png)

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.