Hosting a website on an AWS EC2 instance can seem daunting if you're new to cloud computing, but it’s a powerful and scalable solution for web hosting. This guide will walk you through the process step-by-step, from setting up your EC2 instance to deploying your website.
If you don’t already have an AWS account, follow these steps:
1. Visit the AWS homepage and click on "Create an AWS Account".
2. Fill out the registration form with your email, password, and other details.
3. Verify your email and provide billing information.
4. Choose a support plan and complete the sign-up process.
A Step-by-Step Guide for Creating an AWS Account. Click here
1. Navigate to the EC2 Dashboard:
2. Launch an Instance:
3. Configure Instance Details:
4. Add Tags:
5. Configure Security Group:
6. Review and Launch:
Open your terminal.
Navigate to the directory where your key pair file is located.
Eg: Your file is located in the ‘test’ directory.
icacls.exe your_key_name.pem /reset
icacls.exe your_key_name.pem /grant:r "$($env:username):(r)"
icacls.exe your_key_name.pem /inheritance:r
ssh -i "your-key-pair.pem" ubuntu@your-ec2-public-dns
You can get your EC2 Public DNS from here:
sudo apt update
In the terminal window use the SSH command to connect to your EC2 instance. The basic syntax for the SSH command is:
ssh -i /path/to/your-key-pair.pem ec2-user@your-instance-public-dns
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
1. Create a simple website.
cd ~
mkdir “new-folder-name”
cd “new-folder-name”
echo ‘<html><head><title>My Web Page</title></head><body><h1>Hello World!</h1></body></html>’ > index.html
2. Upload your website files to the web server directory. For Apache, this is typically /var/www/html/:
sudo cp -r /path/to/your/website/* /var/www/html/
3. Set the correct permissions for your files:
sudo chown -R www-data:www-data /var/www/html/
1. Open your web browser and navigate to your instance’s public DNS or your domain name.
2. Check that your website loads correctly and that all links and resources are functioning.
By following these steps, you can successfully host a website on an AWS EC2 instance. This setup provides flexibility, scalability, and control over your web hosting environment. AWS offers a range of tools and services to further enhance your website's performance, security, and management, making it an excellent choice for both small and large-scale web projects. Happy hosting!