Categories: CentOSLinuxShell

How to Install and Configure Apache on Rocky Linux

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

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

# sudo systemctl enable httpd && systemctl start httpd

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

# systemctl status httpd

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

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.

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>

ServerName www.vitux.com

ServerAlias vitux.com

DocumentRoot /var/www/html/

ServerAdmin admin@vitux.com

</VirtualHost>

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

<html>
 <head>
  <title>Welcome to Vitux.com</title>
 </head>
 <body>
  <h1>Success! The vitux.com virtual host is working fine!</h1>
 </body>
</html>

Test Virtual Host result

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

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

Conclusion

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

Vitux Staff

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago