How to install and configure Apache on Rocky Linux

Apache HTTP server is one of the most widely used web servers in the world. It is a free, open source, cross-platform web server that offers powerful features such as loadable modules, strong media support, and extensive integration with other software.

Apache HTTP server is one of the most widely used web servers in the world. It is a free, open source, cross-platform web server that offers powerful features such as loadable modules, strong media support, and extensive integration with other software. It is part of the LAMP server stack (Linux, Apache, MySQL and PHP). By default, HTTP operates on port 80 and HTTPS operates on port 443 of TCP. This tutorial will show you how to install and manage Apache web server on Rocky Linux.

Install 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

Once the installation is complete, enable and start the service with the following command.

# sudo systemctl enable httpd && systemctl start httpd

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

# systemctl status httpd

How to install and configure Apache on Rocky Linux Picture 1How to install and configure Apache on Rocky Linux Picture 1

Enable ports on the firewall

To allow others to access the HTTP or HTTPS service, add a firewall rule.

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

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

# sudo firewall-cmd –reload

You can access the default page to check if the Apache service is running smoothly by entering the server's IP address into your web browser and pressing Enter.

How to install and configure Apache on Rocky Linux Picture 2How to install and configure Apache on Rocky Linux Picture 2

This page indicates that the Apache service is working fine.

Apache Management

Apache is controlled by applying directives in the configuration file.

  1. Apache configuration files are located in the /etc/httpd directory.
  2. Apache's main configuration file is /etc/httpd/conf/httpd.conf.
  3. The file with the .conf extension in the /etc/httpd/conf.d/ directory is also included in the main Apache configuration file.
  4. To load different modules in the configuration file, /etc/httpd/conf.modules.d is used.
  5. The Apache log files for error_log and access_log files are located in the /var/log/httpd/ directory.

Set up Virtual Host (recommended)

To host multiple websites on Apache, Virtual Host is being used. To configure Virtual Host, add the following lines to the end of the configuration file (/etc/httpd/conf/httpd.conf).

ServerName www.vitux.com ServerAlias ​​vitux.com DocumentRoot /var/www/html/ ServerAdmin admin@vitux.com

Restart the service using the following command.

# sudo systemctl restart httpd

Create a sample page named index.html in the /var/www/html/ directory.

# sudo vim /var/www/html/index.html
Welcome to Vitux.com

Success! The vitux.com virtual host is working fine!

Check the Virtual Host results

To check the Virtual Host results, open a browser and enter the server URL

How to install and configure Apache on Rocky Linux Picture 3How to install and configure Apache on Rocky Linux Picture 3

The article has successfully set up and tested Virtual Host without any errors.

4 ★ | 1 Vote