The Apache HTTP server is one of the world’s most widely used web servers. It is a free, open-source, cross-platform web server that offers powerful features such as loadable modules, robust media support, and extensive integration with other software. It is part of the LAMP server stack (Linux, Apache, MySQL, and PHP). By default, HTTP works on port 80, and HTTPS works on port 443 of TCP. This tutorial will teach us how to install and manage the Apache web server on Rocky Linux. So, let’s get started.

Installing Apache

Apache is available on default Linux repositories. The name of the package is ‘httpd’. To install Apache navigate to the terminal and type the following command.

# sudo dnf install –y httpd

Install Apache web server

Once the installation is completed, enable and start the service using the following command.

# sudo systemctl enable httpd && systemctl start httpd

Enable web server to be started at boot time

To verify the service is running, use the following command.

# systemctl status httpd

Check server status

Enable port on Firewall

To allow the HTTP or HTTPS service to be accessible to other people, add the firewall rule.

# sudo firewall-cmd –add-service=https –permanent

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

Reload the firewall to reflect changes by using the following command.

# sudo firewall-cmd –reload

Open http port in the firewall

You can access the default page to test if the Apache service is running smoothly by typing the IP address of your server in the web browser <http://server IP-address> and pressing enter.

Test apache web server

The page indicates that the Apache service is working fine.

Managing Apache

Apache is controlled by applying directives in the configuration file.

  • Apache configuration files are located in the /etc/httpd directory.
  • Apache’s main configuration file is /etc/httpd/conf/httpd.conf.
  • The file with .conf in the /etc/httpd/conf.d/ directory is also included in apache main configuration file.
  • To load the various modules in the configuration file, /etc/httpd/conf.modules.d is used.
  • Apache log files for error_log and access_log files are located under the /var/log/httpd/ directory.

Setting Up Virtual hosts(Recommended)

For hosting multiple websites on Apache, a Virtual Host is being used. To configure the virtual host, append the following lines at the end of the configuration file (/etc/httpd/conf/httpd.conf).

<VirtualHost *:80>



DocumentRoot /var/www/html/

ServerAdmin [email protected]


restart the service by using the following command.

# sudo systemctl restart httpd

Create a sample page with the name index.html under /var/www/html/ directory.

# sudo vim /var/www/html/index.html

  <title>Welcome to</title>
  <h1>Success! The virtual host is working fine!</h1>

Test Virtual Host result

To test up your virtual host result, open up the browser and type the server URL <http://<IP address>.

Apache virtual host

We have successfully set and tested the virtual host without any errors.


In this tutorial, we successfully installed and configured the Apache server on CentOS8 using virtual hosts.

How to Install and Configure Apache on Rocky Linux