How to Host Your Website on AWS EC2: A Step-by-Step Guide

Hosting a website on an AWS EC2 instance is a powerful and flexible option for many developers and businesses. This guide will walk you through the process of setting up a web server on an AWS EC2 instance using Amazon Linux, installing the necessary software, and deploying your website.

Prerequisites

Step 1: Become the Root User

First, connect to your EC2 instance via SSH. Once connected, switch to the root user to ensure you have the necessary permissions for all operations:

sudo su -

Step 2: Update Your Instance

Ensure your instance is up-to-date with the latest security patches and software updates:

yum update -y

Step 3: Install the Web Server

Install Apache HTTP Server, one of the most popular web servers:

yum install -y httpd

Step 4: Check the Status of Apache

Verify that the Apache HTTP Server is installed and check its status:

systemctl status httpd

Step 5: Create a Directory for Your Files

Create a temporary directory to manage your website files:

mkdir temp
cd temp/

Step 6: Download Your Website Files from GitHub

Copy your website files from a public GitHub repository. Use the wget command to download the zip file:

wget https://github.com/ranjithkumarmadhavan/test/archive/refs/heads/main.zip

Step 7: List the Files in the Directory

Verify that the files have been downloaded by listing the contents of the directory:

ls -lrt

Step 8: Unzip the Downloaded File

Extract the contents of the zip file:

unzip main.zip

Step 9: Move Files to the Web Server Directory

Move the extracted files to the Apache web server’s root directory:

mv * /var/www/html/

Step 10: Change to the Web Server Directory

Navigate to the web server’s root directory:

cd /var/www/html

Step 11: Verify Apache Status

Ensure that Apache is running correctly:

systemctl status httpd

Step 12: Enable Apache to Start on Boot

Enable Apache to start automatically when the server boots:

systemctl enable httpd

Step 13: Start the Apache Server

Finally, start the Apache web server:

systemctl start httpd

Feel free to check out the video version of this task on my YouTube channel.

Conclusion

By following these steps, you have successfully set up a web server on an AWS EC2 instance and deployed your website. Your site should now be accessible via the public IP address or domain name associated with your EC2 instance. Regularly update your server and monitor its status to ensure continuous operation.

Leave a Comment