How to Use an AWS EC2 Amazon Linux 2 Server To Deploy an Apache Web Server

Michael Johnson
8 min readJun 2, 2024

--

Back again. Today I will be going over a project that will showcase how to use the AWS CLI to install Apache Web Server on an EC2 Amazon Linux 2 Server and then enable it. Why would we want to do that? Glad you asked.

Apache Web Server, commonly called “Apache,” is a free, open-source software that hosts websites and web applications. It is one of the world’s most widely used web server software, powering over half of the websites on the Internet. So chances are you’ve probably used Apache passively whether you realized it or not.

Apache is known for its flexibility and ability to run on various operating systems, including Linux, Windows, and macOS. It supports various programming languages, including PHP, Perl, and Python, and can be configured to work with various database systems, such as MySQL and PostgreSQL.

Apache is designed to be highly customizable, with a modular architecture that allows administrators to add or remove features as needed. It also includes a wide range of security features, such as SSL/TLS encryption and support for digital certificates, to help protect websites and web applications from potential security threats.

Overall, Apache is a reliable and powerful web server software that provides a secure and efficient platform for hosting websites and web applications.

Okay you may stilll asking yourself how does this look in practice. Well, let’s get started with our example.

As a junior cloud engineer at Level Up Bank, our team has been tasked with creating a new web server using Amazon Linux 2, an open-source Linux distribution widely used for web servers. The web server will host the bank’s website, providing information about its services and allowing customers to access their accounts online.

WHAT TYPE OF SERVERS DO BANKS LIKE THE LEVEL UP BANK USE NOW?

Banks often use various servers on-premises that can be migrated over to Linux, depending on their specific needs and infrastructure. Some of the most common types of servers used in the banking industry include:

  • Database servers: Banks use database servers to store and manage large amounts of financial data, including customer account information, transaction records, and other sensitive data.
  • Application servers: Banks use application servers to run software applications that are critical to their operations, such as online banking systems, payment processing applications, and risk management software.
  • Web servers: Banks use web servers to host their websites and provide online services to their customers.
  • File servers: Banks use file servers to store and manage files and documents, such as employee records, customer statements, and legal documents.
  • Email servers: Banks use email servers to manage their email communication, which is an important part of their daily operations.

All these servers can be migrated to a Linux-based environment, providing improved performance, increased security, and lower costs. Migrating to Linux can also provide banks with greater flexibility and customization options, and access to open-source software and tools.

WHY WOULD THE LEVEL-UP BANK USE APACHE ON LINUX FOR THE NEW SERVER?

A bank may use an Apache web server on Linux for various reasons. Some of the most common reasons include the following:

  • Stability and reliability: Apache web server is known for its stability and reliability, making it a popular choice for critical applications, such as those used by banks.
  • Performance: Apache web server is highly scalable and can handle large amounts of traffic, making it an ideal choice for banks that need to support a high volume of online transactions.
  • Security: Apache web server is considered very secure, with a strong focus on security features and a large community of users who work to identify and address security vulnerabilities.
  • Flexibility: Apache web server is highly customizable, with a wide range of plug-ins and modules available that can be used to add functionality and tailor the server to meet the bank’s specific needs.
  • Cost: Apache web server is open-source software, meaning it is free and can be used without licensing fees. This can help banks to reduce their overall IT costs.

Using an Apache web server on Linux allows a bank to take advantage of these benefits and provide a secure, high-performance platform for its online applications and services.

So let’s get started and migrate our website.

Prerequisite

  • AWS Account
  • AWS CLI Installed
  • Amazon Linux EC2 Instance(s) Running with Port 22 and Port 80 open to Anywhere
  • Basic Background of Creating EC2 Intsances and SSH (Refer here to my previous post where we made an EC2 Instance using the AWS console and SSH into it)

Step One- Using our Terminal to Install Apache

So with our created EC2 instance called “Bankserver” let’s SSH into our instance.

We will first check to see if we need any updates on our server. To do this we can type the following command into the terminal

sudo yum update -y

The sudo (Super User DO) allows us to run commands as a Superuser. Basically that means we can run commands as an admin with all permissions. Unfortunately it doesn’t let us jump buildings in a single bound or be faster than a speeding bullet. Sigh…

The yum (Yellowdog Updater Modified) command allows users to search, update, install, or remove software packages.

So when we combine sudo with yum and type “update” we as an admin are telling our machine to search for any updates that may exist. The “-y” option tells our terminal that we want to say “yes” to any questions. Okay so did we have any updates? Let’s see below

Nope. We didn’t have any updates available. That’s means it’s time to install our Apache Webserver. Before we do that we can check to see if it already is installed on our EC2 instance. To do that we will type the following command in

rpm -q httpd

The rpm (Red Hat Package Manager) command allows us to interact with packages on our system . So with the option -q we are querying our system to see if Apache(called httpd) is installed or not.

As we can see Apache(httpd) is not installed. So we can go ahead and type in

sudo yum install httpd -y

After doing so we should be greeted by a screen like this:

And bingo!! Our Apache Webserver is installed. Now we can move on to enabling our webserver

Step Two: Enabling our Webserver

A little shout out to my colleagues in LUIT

Now that our Apache web server is installed we can go ahead and start on enabling it for use. The first thing we will want to do is make sure our Apache server is running to do this type

sudo systemctl start httpd

The “systemctl” command allows us to control the system and service manager of our machine. Since we know Apache exists on our server by typing this in we are telling it to wake up and get to work. But like any worker it needs to coffee to get its day started to enable it to work properly.

To enable our Apache web server we will now type in

sudo systemctl enable httpd

And with that our Apache is wide awake and ready to get to work.

Let’s check though to make sure everything is in proper order though. To check on our Apache to make sure it’s running properly we can type in

sudo systemctl status httpd

which will give us a long list of info like this

As we can see our Apache is running and enabled. Now we can proceed to our final step

Step 3: Visit our Website

To do this we simply need to type our public IP address into a web browser and see if web server can load. To get the IP address you can go back to your AWS console and copy your public IP address and paste into a web browser. After doing so you should get a page that looks like this

And there we go. Our web server is live. This is the default Apache test page. This is kinda boring so as a bonus I’ll make a very simple webpage.

Bonus Step

To make a custom webpage we will need to an HTML file. To get started type

cd /var/www/html

After doing so type

sudo nano index.html

This will allow use to write in our index.html file. Though it may be easier to first go to a text editor application like Visual Code Studio and then paste into our Nano text writer. I do so and made this very basic HTML file

After pasting this into Nano I press ctrl O on my keyboard to save it, pressed enter to confirm, and then pressed crtl x to exit. After doing so now when I go to my public IP address I get this

Awesome!!!

Conculsion

I hope this was a helpful demostration. Next time we will look into what to do if you have users reporting issues with the website. We show how to check the logs to see where an error may be coming from. Thanks again and until next time see you.

--

--