How to Install Apache on CentOS 8

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 article, we’ll explain how to install and manage the Apache webserver on CentOS 8.
Installing Apache
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
:
sudo yum install httpdOnce the installation is complete, enable and start the Apache service:
sudo systemctl enable httpd
sudo systemctl start httpdTo verify that the service is running, check its status:
sudo systemctl status httpdThe output should look something like this:
● 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
...Adjusting the Firewall
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:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reloadManaging Apache
This section explains how the Apache configuration files are structured and the best practices for managing the Apache webserver.
- All Apache configuration files are located in the
/etc/httpddirectory. - The main Apache configuration file is
/etc/httpd/conf/httpd.conf. - Configuration files ending with
.conflocated in the/etc/httpd/conf.ddirectory are included in main Apache configuration file. - Configuration files that are responsible for loading various Apache modules are located in the
/etc/httpd/conf.modules.ddirectory. - Apache vhost files must end with
.confand be stored in/etc/httpd/conf.ddirectory. You can have as many vhosts as you need. Creating a separate configuration file (vhost) for each domain makes the server easier to maintain. - It is a good practice to follow a standard naming convention. For example, if the domain name is
mydomain.comthen the configuration file should be namedmydomain.com.conf
- It is a good practice to follow a standard naming convention. For example, if the domain name is
- Apache log files (
access_loganderror_log) are located in the/var/log/httpd/directory. It is recommended to have a differentaccessanderrorlog files for each vhost. - You can set your domain document root directory to any location you want. The most common locations for webroot include:
/home/<user_name>/<site_name>/var/www/<site_name>/var/www/html/<site_name>/opt/<site_name>
Conclusion
Congratulations, you have successfully installed Apache on your CentOS 8 server. You’re now ready to start deploying your applications and use Apache as a web or proxy server.
You can manage the Apache service in the same way as any other systemd unit.
If you have any questions or feedback, feel free to leave a comment.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page