Installing Apache Web Server on CentOS 9

Introduction

Apache is an open-source web server software that is widely used on the Internet to serve web pages. It is developed and maintained by the Apache Software Foundation and is the most popular web server software in use today. Apache2 is known for its stability, flexibility, and security, and can be easily configured to serve different types of web content, such as HTML, PHP, and CGI scripts. It also supports a variety of operating systems, including Windows, Linux, and macOS.

Prerequisites

  1. CentOS up and running Linux machine
  2. Root permission
  3. Intenret connectivity
  4. Basic knowledge of linux commands

You will learn how to set up an Apache web server on your CentOS 9 Linux server in this guide.

Step 1: Update System Packages

You need to update the CentOS current repository by following the given commands, This will update the apache repository.

sudo yum update

Step 2: Installing Apache

Apache can be installed using standard package management tools because it is included in CentOS’s default software repositories, You just execute the given command.

sudo yum install httpd

Step 3: Start Apache and Enable it on Boot

We can use the following command in order to start and enable Apache service on system boot time.

To start Apache service.

sudo systemctl start httpd

To enable on boot apache service.

sudo systemctl enable httpd

Step 4: Opening Apache Ports in Firewall

We need to also open the port 80 and 443 in order to get access Apache server from the network, Use the given command for the same.

To add the port 80 and 443

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

To reload the firewall service.

sudo firewall-cmd --reload

Step 5: Verifying Apache Service

Open a web browser and navigate to your server’s IP address or domain name. You should see the default Apache page if the installation was successful.

http://localhost

Additional Configuration (Optional)

  • To serve a specific directory, you can edit the Apache configuration file at /etc/httpd/conf/httpd.conf.
  • You can install additional modules or configure virtual hosts as needed.

Step 6: SELinux (Optional)

If SELinux is enforcing, you might need to adjust its settings. You can check the SELinux status with:

sestatus

If SELinux is enabled and causing issues, you may need to use setsebool to allow Apache to connect to the network:

sudo setsebool -P httpd_can_network_connect 1

Conclusion

We have successfully installed and carried out the fundamental Apache Web Server tasks; if you still have questions, please post them in the comments section below.

Author

Installing Apache Web Server on CentOS 9

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top