Creating an EC2 Instance with an Apache web server
By: James Banks
Tags: Ec2, AWS, Ec2 Instance, Apache

What is an EC2 Instance?

An Amazon EC2 instance is a virtual server in Amazon’s Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure. EC2 is a service that enables subscribers to run application programs in the computing environment. It can serve as a practically unlimited set of virtual machines (VMs).

Amazon provides various types of instances with different configurations of CPU, memory, storage and networking resources to suit user needs. Each type is available in various sizes to address specific workload requirements.

What is Apache?

Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web.

What we’ll be doing in this scenario is creating an EC2 instance with an Apache web server. Our task is to use a script that will update all packages on the server, install Apache, and then start the service upon launching. We will be doing all of this through the AWS console.

This process is fairly quick and simple so let’s get started…

First, we’ll need to log into our AWS account. I’ll be logging into a user account created with admin privileges. Best practice is to use a user account, not your root account. Once your logged in, navigate to the EC2 console. You can simply type “EC2” in the the search bar at the top of the page. Once your on the EC2 console click on “Launch Instance.”

We’ll first be prompted to select an Amazon Machine Image (AMI). This is where EC2 Instances are created from. We can select the “Amazon Linux 2 AMI” image.

Next we’ll be prompted to choose an Instance type. For this scenario our type will be “t2.nano”. After selecting that type, click on “Next: Configure Instance Details” at the bottom right of the page.

On this page we can stick with all the defaults and simply scroll to very bottom of the page. Here in the “User Data” section under “Advanced Details” is where we will input our script to install the Apache web server. See the script below:

After inputting the script in the “User Data” section click “Next” until you arrive on the “Configure Security Group” page. Here we’re gonna create a new security group and add a couple of rules. We’re gonna select both HTTP and HTTPS as these are the ports that Apache listens from by default (80, 443.)

Next select “Review and Launch” and then “Launch”. Then you will be prompted to select an existing key pair or create a new one. If you need to generate a new key pair be sure to save the key pair credentials in your personal files.

Once you’ve launched the Instance, verify back in the EC2 console that your Instance is in a running state.

Next we’ll need to verify that Apache has in fact been installed at the launch of our Instance. We can do this by selecting the instance and then retrieving the public IP address. Copy the IP address and paste it into your browser in a new tab. If successful you will see the Apache Test page.

And that’s how it’s done! Congratulations!