Setting Up Amazon Linux EC2 Instance for Web Server Installation
A web server is a software application that uses protocols like HTTP and HTTPS to respond to requests from clients over the World Wide Web. Its main functions are to store website content, process HTTP requests, and deliver content to users. It can deliver both static and dynamic content. Some popular web server software examples include Apache, Nginx, Microsoft IIS.
For this article I will be using Apache HTTP Server(httpd) for our web server.
Task 1: Launch an Amazon EC2 Instance
Step 1- Choose an Amazon Machine Image (AMI)
Step 2- Choose an Instance Type
- “t” is the family name.
- “3” is the instance generation.
- “small” is the instance size.
Step 3- Create a Virtual Private Cloud (VPC)
Step 4- Create a Subnet
Step 5- Create an Internet Gateway (IGW)
Step 6- Attach your IGW to your VPC
Step 7- Create a Route Table
Step 8- Edit Routes
Step 9- Configure the Subnet Associations
Step 10- Configure the Network of the EC2 Instance
Step 11- Create a Security Group for the instance
Step 12- Create a user data script to install the Web Server
#!/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "Hello world from $(hostname -f)" > /var/www/html/index.html
sudo chown 766 /var/www/html
Task 2: Display your website
Step 1- Use EC2 Instance Connect to connect to the instance
EC2 Instance Connect provides a secure way to connect to an Amazon Linux 2 or Ubuntu instance using SSH. You can use EC2 Instance Connect to connect to an instance using the Amazon EC2 console, the EC2 Instance Connect CLI, or an SSH client of your choice. With EC2 Instance Connect, you use IAM policies to control the SSH access to the instance. In addition, EC2 Instance Connect logs all connection requests to AWS CloudTrail so that you can audit connection requests.
Step 2- configure your access keys
Access keys are credentials that consist of an access key ID and a secret access key. They are used to authenticate and grant programmatic access to AWS services via APIs, SDKs, or command-line tools.
Step 3- Move your website file to the directory of the instance
sudo cd /var/www/html
sudo ls /var/www/html
Step 4- Display your Website
Conclusion
Setting up an Amazon Linux EC2 instance for web server installation involves following the above steps. After these steps, the web application will be running and accessible to users.