Setting Up Amazon Linux EC2 Instance for Web Server Installation

precious ogundipe
4 min readNov 20, 2023

--

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)

select Amazon Linux 2 as the AMI

Step 2- Choose an Instance Type

select t3.small instance type name
  • “t” is the family name.
  • “3” is the instance generation.
  • “small” is the instance size.

Step 3- Create a Virtual Private Cloud (VPC)

VPCs are assigned a CIDR block, which is a range of IP addresses that you can use to define your private network.

Step 4- Create a Subnet

VPCs can be divided into subnets, which are smaller networks that can be used to further isolate your resources.

Step 5- Create an Internet Gateway (IGW)

internet gateway is a network that connects a virtual private cloud (VPC) to the public internet.

Step 6- Attach your IGW to your VPC

Attaching your internet gateway to your VPC is essential for enabling connectivity.

Step 7- Create a Route Table

This is used to define how traffic is routed within your VPC and to the public internet.

Step 8- Edit Routes

specify the Ip address that passes through the internet gateway

Step 9- Configure the Subnet Associations

Subnet associations are used to link subnets within a Virtual Private Cloud (VPC) to route tables. This association determines the routing behavior for the resources within those subnets.

Step 10- Configure the Network of the EC2 Instance

Step 11- Create a Security Group for the instance

Security Groups are used to control access to your instance based on IP addresses and ports.

Step 12- Create a user data script to install the Web Server

This script will install Apache HTTP 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.

configured access key details

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

congratulations you’ve configured your webserver 👏 👏

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.

--

--