AWS EC2 instances | Apache | Bash

Anthony Wint
5 min readJul 11, 2022

What is EC2?

To put it simply, an EC2 is a virtual machine that represents a physical server for you to deploy your applications. Instead of purchasing your own hardware and connecting it to a network, Amazon gives you nearly unlimited virtual machines to run your applications while they take care of the hardware.

What is Apache and why it is used?

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 is a Bash script?

A Bash script is a text file containing a series of commands. Any command that can be executed in the terminal can be put into a Bash script.

Here is the scenario… Your company wants to start shifting from using on-premises servers to using servers in the cloud. Rather than purchasing all the infrastructure in a data center, they ask you to create an EC2 instance in AWS to host their new website.

Objectives

  1. Launch an EC2 Amazon Linux t2.micro (free tier) in a public subnet.
  2. 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.
  3. SSH into your EC2 instance and install Apache with a custom webpage using a BASH script. (The webpage can be a simple Hello World or something more complex.

Step 1. You will need to search for EC2 in the AWS console and click on it.

Step 2. Click where it says launch instance.

Step 3. you are going to want to name your instance then scroll down and create a key pair. Once the key pair is created you need to download, save and keep it in a SAFE place.

Step 4. When setting up your key pair you will need to 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.

Warning: you must keep the key pair safe place from hackers!!!

Once the key pair is created and put into a safe place now you can Launch Instance.

As you can see your instance is up and running.

SSH into your EC2 instance and install Apache with a custom webpage using a BASH script. (The webpage can be a simple Hello World or something more complex.)

Step 5. you will have to hit connect then SSH Client which shows you commands on how to SSH into your E2C instance.

For this, you are going to need to open up a terminal and sign in. Once you sign you will now need to:

a. Know where you have secured your key pair.

b. cd (change directory) into the file that has an EC2 instance.

c. Copy the example command and put it into your terminal

Now we are in the EC2 instance!!!!!!!

Step 6. Installing Apache web server.

How do I install an Apache web server on an AWS EC2 instance?

On your EC2 instance, install the Apache web server and configure it as follows:

Connect to your EC2 instance and install the Apache web server.

                    sudo yum -y install httpd

Start the service. Use command

                        sudo service httpd start

Go ahead and test your IP address to make sure the Apache web server is downloaded and started up correctly. Open up your browser and put in your IPv4 address.

Step 7. You now install Apache!!!! Make a custom web page with the Bash script. Be sure to execute the script once done.

                           vim <script>

Here’s my script…

Use this command to execute your script.

                        chmod +x <filename>

Step 8. Locate your public IP address, type it in your browser, and watch what you wrote on your script come alive on your screen.

You have now completed that task given to you by your company using an EC2 instance!

--

--