Installing Apache Web Server on AWS EC2

Fernando J. Robert
5 min readDec 7, 2022

--

Hi everyone on this tutorial provides instructions on how to create a t2.micro EC2 instance with an Apache. A script will be used to update software packages and install and enable the Apache server.

Process:

· Launch an EC2 Amazon Linux t2.micro (free tier) in a public subnet.

· Create a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from your IP address.

· SSH into your EC2 instance and install Apache with a custom webpage using a BASH script.

Prerequisites:

AWS console access

IAM User account

VIM

First we need to know what is AWS?

Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 200 fully featured services from data centers globally. Millions of customers — including the fastest-growing startups, largest enterprises, and leading government agencies — are using AWS to lower costs, become more agile, and innovate faster. For more information go to https://aws.amazon.com/ to learn more.

Ok so we got that out of the way we can start.

Step 1: Sign into Amazon Web Service Management Console with IAM user credentials and MFA code.

Step 2: On the search bar, type in EC2 to access dashboard, then click Launch instance. Make sure that you are in us-east-1 Region North Virginia.

Step 3: Give the EC2 Instance a name then choose Amazon Linux 2.

Step 4: Now for the Instance type select t2.micro and create a new keypair.

Step 5: Name your key pair and select key pair configurations and click create new key pair.

Step 6: Next we need to create a security group and connect to your EC2 instance. Click create security group, and review network settings. You can allow HTTS from the internet and allow SSH from only your pc. Make sure that all of the check mark are check.!

Step 7: We’re going to bypass the remaining menus then take look at the summary to ensure all of configurations for the EC2 instance are correct, then click launch instances.

If you did right you should get this message, make sure that your instance is running.

Step 8: Click on the EC2 menu button and click on “Network Settings” and select Security Group.

Step 9: Select “launch-wizard-1 and click edit inbound rules.

Step 10: Click Add Rule after that you will select the configurations, for the “Type” select SSH and for the source “Type” select My IP the click save rules. See the example below.

Step 11: Let’s go back to the Instances from the menu and select your running instances and on details view the public IP address and copy it. Now click on connect and take a look at the username for the instance.

Step 12: Open Windows PowerShell and switch to the directory that contains the private access key and finally the SSH in the EC2 instances.

Ok so far good?? let’s continue.

Now comes the fun part! We need to create a bash shell script to install Apache webserver!

Type this command on your terminal:

sudo su -
pwd

Now run this command to create a shell (vim apache-server.sh) this will open vim text editor.

Great you should now see the vim editor.! We’re almost done now copy what I have in my Vim make sure to start with {#!/bin/bash}) on the top. If you forgot or don’t know how write on Vim make sure that, press (i) on your keyboard to switch into insert mode so that you can start editing the file. Once you write and edit press the ESC button and then type (:wq!) to save and quit vim editor. Here’s an example:

Ok so we are almost at the end! we need to change the permissions in order to accomplish the script.

chmod 744 apache-server.sh

To view the permissions of the file, type this command:

ls -al apache-server.sh

Now….Time to run this!!! type this command to run the script:

./apache-server.sh

One more step and will be done!, open a web browser and enter the IP address from your EC2 instances if you see your comments on the web page you have done it.!

Congrats! you have done it you have install Apache Web Server on your AWS EC2.

--

--