Static Website Deployment on AWS EC2
In today's dynamic tech landscape, the deployment of static websites stands as a cornerstone skill for navigating the digital realm. With an emphasis on Amazon EC2 instances and the Apache HTTP Server (httpd) on AWS Linux, this project offers a comprehensive guide to deploying static websites.
Prerequisites
An AWS account
Basic understanding of AWS services
Familiarity with Linux commands
Step 1: Launching an EC2 Instance
Sign in to your AWS Management Console.
Navigate to the EC2 dashboard.
Click on "Launch Instance" and select an Amazon Linux AMI.
Choose an instance type and configure instance details.
selecting an existing key pair or creating a new one.
Review and launch the instance,
Note: I have a static website for an E-commerce bookstore web application that I used for deployment. If you have any other projects, feel free to use those instead.
Step 2: Connecting to the EC2 Instance
Once the instance is running, note its public IP address.
Open a terminal or SSH client.
Use SSH to connect to the instance:
ssh -i your-key.pem ec2-user@your-instance-public-ip
Replace
your-key.pem
with the path to your private key file andyour-instance-public-ip
with the public IP of your EC2 instance.
Step 3: Setting Up the Web Server
Switch to the root user:
sudo su -
Update the package repository and install the Apache HTTP Server:
yum update -y yum install -y httpd
After executing the commands, the setup resembles the image below.
Create a directory to organize your website content. You can name it according to your preference, such as mkdir <directory name>, or if you prefer to proceed without creating a directory, you can continue as well:
mkdir digilib cd digilib
To obtain your website files, you have the option to either download a zip file hosted on GitHub or utilize your own web project files. If opting for GitHub, navigate to the repository, click on the "Code" dropdown menu, select "Download ZIP," and copy the provided link. Then, right-click on the "Download ZIP" button and select the "Copy link address" option. Finally, use the copied link with the
wget
<your repository link> command to retrieve the files, as outlined below.wget https://github.com/HemanthGangula/Static-Website-AWS-EC2-Apache/archive/refs/heads/main.zip
After executing the command, use the 'ls' command to list the contents. You should observe a file named 'main.zip'.
Unzip the downloaded zip file:
unzip main.zip
Move the contents of the unzipped folder to the Apache document root directory:
mv * /var/www/html
Navigate to the document root directory:
cd /var/www/html
Step 4: Configuring the Web Server
Ensure that inbound rules for your EC2 instance's security group allow traffic on ports 80 and 443.
Check the status of the Apache service:
systemctl status httpd
Enable the Apache service to start on boot:
systemctl enable httpd
Start the Apache service:
systemctl start httpd
Step 5: Verifying Deployment
Open a web browser and enter your EC2 instance's public IP address.
You should see your static website up and running.
In my case, the output of the website appears as follows after hosting.
Thanks to Meghana, the website has been contributed.
You can view my website at the following link: http://34.201.122.99/
In my case, I didn't add a custom domain for the website. However, if you need to do so, I can provide simple steps to guide you through the process in the next article.
Congratulations! You have successfully deployed a static website on an AWS EC2 instance using the Apache HTTP Server. You can now access your website from anywhere with an internet connection. Keep exploring AWS services to enhance your website's capabilities and performance.
Subscribe to my newsletter
Read articles from Hemanth Gangula directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Hemanth Gangula
Hemanth Gangula
๐ Passionate about cloud and DevOps, I'm a technical writer at Hasnode, dedicated to crafting insightful blogs on cutting-edge topics in cloud computing and DevOps methodologies. Actively seeking opportunities in the DevOps domain, I bring a blend of expertise in AWS, Docker, CI/CD pipelines, and Kubernetes, coupled with a knack for automation and innovation. With a strong foundation in shell scripting and GitHub collaboration, I aspire to contribute effectively to forward-thinking teams, revolutionizing development pipelines with my skills and drive for excellence. #DevOps #AWS #Docker #CI/CD #Kubernetes #CloudComputing #TechnicalWriter