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.
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
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.
Apache is controlled by applying directives in the configuration file.
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>
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.
In this tutorial, we successfully installed and configured the Apache server on CentOS8 using virtual hosts.
Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…
ISPConfig is an open-source control panel that allows users to manage multiple servers from a…
As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…
Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…
Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…
phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…