Apache HTTP server is the most widely used web server in the world. It is a free, open-source, and cross-platform HTTP server, including powerful features, and can be extended by a wide variety of modules.
In this tutorial, I explain how to install and manage the Apache webserver on CentOS 8.
Apache is available in the default CentOS repositories, and the installation is pretty straight forward.
On RHEL based distributions, the Apache package and service are called httpd. To install the Apache run the following command as root or user with sudo privileges:
# yum install httpd
Once the installation is complete, enable and start the Apache service:
# systemctl enable httpd --now
To verify that the service is running, check its status:
# systemctl status httpd
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2019-10-12 15:54:58 UTC; 6s ago ...
FirewallD is the default firewall solution on Centos 8.
During the installation, Apache creates firewalld service files with predefined rules for allowing access to HTTP (80)
and HTTPS (443)
ports.
The following commands will permanently open the necessary ports:
# firewall-cmd --permanent --zone=public --add-service=http # firewall-cmd --permanent --zone=public --add-service=https # firewall-cmd --reload
This section explains how the Apache configuration files are structured and the best practices for managing the Apache webserver.
/etc/httpd
directory./etc/httpd/conf/httpd.conf
..conf
located in the /etc/httpd/conf.d
directory are included in main Apache configuration file./etc/httpd/conf.modules.d
directory..conf
and be stored in /etc/httpd/conf.d
directory. You can have as many vhosts as you need. Creating a separate configuration file (vhost) for each domain makes the server easier to maintain.access_log
and error_log
) are located in the /var/log/httpd/
directory. It is recommended to have a different access
and error
log files for each vhost./home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
In the following, the Apache web server will be configured in a basic way. To do this, edit the httpd.conf
and make the following changes.
# vim /etc/httpd/conf/httpd.conf
# line 86: set the server admin email address ServerAdmin root@michu-it.com # Line 95: set the server name ServerName www.michu-it.com # Line 151: Change 'none' to 'All' AllowOverride All # The following is entered at the end of the configuration and serves as a hardening purpose: ServerTokens Prod KeepAlive On
After each configuration change the apache.service must be reloaded or restarted:
# systemctl restart httpd
Further documentation can be found under the individual links