Introduction
Amazon Elastic Compute Cloud (Amazon EC2) is a fundamental service offered by AWS that delivers scalable cloud computing resources. It allows businesses and developers to run applications without requiring physical servers. In this article, we will guide you how to connect to EC2 Instance and Install Web Server.
What is Amazon EC2?
Amazon EC2, users are provided with virtual servers, or more commonly known as instances, on which to execute their applications. You have complete control over the resources allocated to your computer and can scale them up or down depending on your utilization needs with EC2. EC2 is very flexible to different workloads as it offers many instance types, operating systems, and pricing models.
Key Features of Amazon EC2
- Scalability: Change your instance type or capacity according to your needs with Auto Scaling.
- Cost Efficient: Cost can be minimized by selecting On-Demand, Reserved, or Spot Instances.
- OS Support: Users can run virtually any distribution of Linux, Windows, or even develop their own custom operating systems.
- Security: Utilize security groups, network access control lists, and encryption.
- Integration: Seamlessly integrate with other AWS services like S3, RDS, and CloudWatch.
Steps to connect to EC2 Instance and Start the Web Server
In the previous blog, we have seen how to create EC2 Instance and follow the same steps for creating EC2 Instance.
Step 1: Connect to EC2 Instance
Once your instance is running, connect to it using an SSH client.
Step-by-Step Instructions:
- Locate the Public IP Address:
- Go to the EC2 Dashboard.
- Select your instance and copy its public IPv4 address.

2. Open a Terminal (Linux/Mac) or SSH Client (Windows)
Use the following command to connect:
Chmod 400 Keypair
ssh -i keypair ec2-user public ip address
Replace the Keypair and the public ip address of the EC2 Instance
3. Verify Connection
- Once connected, you’ll see a welcome message confirming access to your EC2 instance.

Installing the WebServer
With the instance connected, the next step is to install and configure a web server.
Step-by-Step Instructions:
1. Update the System
Run the following command to update your instance:
sudo yum update -y
2. Install Apache (HTTPD)
Use the following command to install the Apache web server:
sudo yum install httpd -y

3. Start the Apache Service
Start the Apache web server with
sudo systemctl start httpd
sudo systemctl enable httpd

4. Verify Installation:
Open a web browser and enter your instance’s public IP address. If Apache is running, you’ll see the default Apache welcome page.
Configuring the Web Server
You can customize the web server to host your own content.
Step-by-Step Instructions:
1.Navigate to the Web Directory
Apache serves files from /var/www/html. Change to this directory:
cd /var/www/html
2. Add Your Content:
Create or upload an HTML file. For example:
echo “<h1>Welcome to My Web Server</h1>” | sudo tee index.html

3. Test the Content
Refresh your browser. The custom HTML content should appear.

Secure Your Web Server
Security is crucial for any online service.
Best Practices:
- Limit SSH Access:
- Update your security group to allow SSH access only from your IP address.
- Update your security group to allow SSH access only from your IP address.
- Use HTTPS:
- Install an SSL certificate using tools like Let’s Encrypt.
- Install an SSL certificate using tools like Let’s Encrypt.
- Regular Updates:
- Keep your server updated to protect against vulnerabilities.
- Use sudo yum update regularly.
- Keep your server updated to protect against vulnerabilities.
- Monitor Logs:
- Check access and error logs for unusual activity:
- sudo tail -f /var/log/httpd/access_log
- sudo tail -f /var/log/httpd/error_log
Key Benefits of Hosting a Web Server on EC2
- Scalability: Easily handle traffic spikes by scaling instances.
- Flexibility: Customize the instance configuration for your needs.
- Cost-Effectiveness: Optimize costs with Spot Instances or Auto Scaling.
- Integration: Use other AWS services like RDS for databases or S3 for static file hosting.
Common Issues and Troubleshooting
- Cannot Connect via SSH
- Ensure port 22 is open in the security group.
- Verify the correct key pair and IP address are used.
- Web Server Not Responding
- Ensure port 80 is open in the security group.
- Check if Apache is running:
- sudo systemctl status httpd
3. Permission Errors
Fix file permissions in /var/www/html using:
- sudo chmod -R 755 /var/www/html
Scaling Your Web Server
Once your web server is operational, you might have to manage higher levels of traffic and here are the scaling options
- Auto Scaling:
Utilize Auto Scaling Groups to increase or decrease instances according to traffic. - Elastic Load Balancer (ELB):
Route traffic among several instances to ensure high availability.
Conclusion
Well done! You have successfully connected to an EC2 instance and initiated your first web server. By following these steps, you have learned how to start an instance, configure a web server, and host content on AWS. This foundational knowledge is crucial for deploying scalable, secure, and production-ready web applications in the cloud.
Amazon EC2 offers unparalleled flexibility, and by integrating it with other AWS services, you can build robust and highly available architectures. Whether you’re operating a personal website or creating enterprise-level applications, EC2 is a powerful tool to help you achieve your goals
1 Comment
[…] Please follow steps for creating EC2 Instance for this Blog: […]