DEV Community

Cover image for How to Install Apache Web Server on Amazon Linux 2
Mohammad Abu Mattar
Mohammad Abu Mattar

Posted on

How to Install Apache Web Server on Amazon Linux 2

Introduction

In this tutorial, we will learn how to install Apache web server on Amazon Linux 2. We will also learn how to configure Apache web server to run simple HTML web page.

Prerequisites

To follow this tutorial, you will need:

  • An Amazon Linux 2 EC2 instance.
  • A user with sudo privileges.

Install Apache Web Server and run simple HTML web page

Step 1: Install Apache Web Server

Before we start, we need to update the package list and upgrade the installed packages:



sudo yum update -y


Enter fullscreen mode Exit fullscreen mode

Now, we can install Apache web server:



sudo yum install httpd -y


Enter fullscreen mode Exit fullscreen mode

Step 2: Start Apache Web Server

Now, we can start Apache web server:

  • Start Apache Server


sudo systemctl start httpd


Enter fullscreen mode Exit fullscreen mode
  • Configure Apache to run on system boot


sudo systemctl enable httpd


Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Firewall

Now, we need to configure the firewall to allow HTTP traffic:



sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload


Enter fullscreen mode Exit fullscreen mode

Step 4: Create a Simple HTML Web Page

Before we can test Apache web server, we need to change the permissions of the /var/www/html directory:



sudo chmod 777 /var/www/html


Enter fullscreen mode Exit fullscreen mode

Now, we can create a simple HTML web page:



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

Enter fullscreen mode Exit fullscreen mode


<!DOCTYPE html>
<html>
<head>
<title>Apache Web Server</title>
</head>
<body>
<h1>Apache Web Server</h1>
<p>This is a simple HTML web page.</p>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode




Step 5: Test Apache Web Server

Now, we can test Apache web server by opening the public IP address of our Amazon Linux 2 EC2 instance in a web browser:

Apache Web Server

Conclusion

In this tutorial, we learned how to install Apache web server on Amazon Linux 2. We also learned how to configure Apache web server to run simple HTML web page.

References

Top comments (0)