- Published at
Install Apache on AWS Linux EC2
Guide to install Apache on AWS.
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:
-
Your instance has a public DNS name that is reachable from the internet. For more information, see Auto-assign Public IP in the Network settings section and Create a security group.
-
The security group associated with your instance is configured to allow SSH (port 22) traffic so that you can connect to the instance to view the output log files. For more information, see Create a Security Group.
-
Your instance is launched with an Amazon Linux 2 AMI. These instructions are intended for use with Amazon Linux 2, and the commands and directives may not work for other Linux distributions. For more information about other distributions, such as their support for cloud-init, see their specific documentation.
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:
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:
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:
After the index.html file is saved, reload the web services:
That’s it! Good luck with your testing!