Skip to content

Install Apache on AWS Linux EC2

Published: at 07:35 AM

Table of contents

Open Table of contents

Introduction

I recently performed testing with an AWS Application Load Balancer (ALB) and needed to spin up three web servers in EC2 quickly. I decided to use the option of passing “User Data” and run Linux commands at launch to install Apache.

This is a simple example, if you want to learn more, you can visit this link.

Install Apache

Prerequisites

The examples in this article assume the following:

The Process

After you have met all the prerequisites, go ahead and begin to launch your instance. Select all the details for your needs- Networking, Storage, etc. and navigate to the “Advanced details” section. Scroll down to locate the “User data” section and paste the following in the text field:

#!/bin/bash
yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd

The instance will now launch and run the commands to install Apache. When you log into the instance, you can check and confirm Apache is up and running by the following command:

service httpd status

For my testing purposes, I wanted to make sure I knew which web server I was hitting from the ALB. I went ahead and configured a simple web page with the following configuration steps:

sudo systemctl edit httpd
#add the following line to the config file
Directory "/var/www/html"
cd /var/www/html

sudo touch index.html
sudo vi /var/www/html/index.html

After the index.html file is saved, reload the web services:

sudo systemctl reload httpd

That’s it! Good luck with your testing!