How to Install Apache Web Server on Red Hat Enterprise Linux 9

How to Install Apache Web Server on Red Hat Enterprise Linux 9

Apache is a free and open-source HTTP server. It was first released in 1995 by Apache Software Foundation. It is a cross-platform web server and can run on both Windows and Linux or Unix-like operating systems.

It runs on 67% of web servers worldwide. It is fast, secure, and reliable. It is customizable to meet the needs of different environments by using extensions and modules.

HTTPD is a software program that runs in the background of a web server and waits for incoming server requests. The daemon answers the requests automatically and serves the hypertext and multimedia documents over the internet using HTTP.

In this article, we will explore the method to install the Apache web server on Red Hat Enterprise Linux 9.

Prerequisites

  • RHEL instance
  • Root account or a user with sudo privileges

Install Apache Web Server on Red Hat Enterprise Linux 9

Install Apache web server

Fire up the terminal from the activities menu and run the following command to install apache web server on your system.

yum install httpd

Open TCP port 80

Open TCP port 80 (which is the default port used by Apache) in the firewall. You should run:

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

Start Apache Web service

When you have successfully installed the web server, you can start its service as follows.

systemctl enable --now httpd

Check the status

Type the following command to check the status of Apache web server. It must show active and running.

systemctl status httpd

Stop the Apache service

You can stop the Apache web service by executing the command on the terminal.

systemctl stop httpd

Restart the Apache service

You can restart the Apache web service with the help of below command.

systemctl restart httpd

Access the Apache web page

As you have successfully installed the Apache web server, you can now access the web page by typing local host in your browser. You will get a test page.

localhost

Insert files in /var/www/html directory

By default, Apache web server serves the Red Hat Enterprise Linux Test Page when accessed. You can add your own files in the /var/www/html directory. Suppose we want to add the new file example.html.

You should run:

sudo nano /var/www/html/example.html

Insert ‘This is a test page’ in the newly created example.html file and save it.

Access the following page from your browser.

localhost/example.html

Remove Apache Web Server from Red Hat Enterprise Linux 9.

If you no longer keep the Apache web server on your system, you can delete it along with dependencies with just a single command. you would run:

sudo yum remove httpd

Conclusion

We have listed down the steps to install Apache web server on your RHEL 9. If you have any questions, send us through comments. Keep visiting Linux World.