This article will talk about how to instal and run the Apache web server on CentOS 8.
The most popular web server worldwide is Apache HTTP server. It is a powerful, open-source, free, and cross-platform HTTP server that can be expanded with a huge selection of modules.
The installation of Apache is fairly simple and includes access to the default CentOS repositories.
httpd is the name of the Apache package and service on RHEL-based distributions. Run the following command as root or a user with sudo permissions to install Apache:
sudo yum install httpd
After installation is finished, turn on and launch the Apache service:
sudo systemctl enable httpd
sudo systemctl start httpd
Check the service’s status to ensure that it is active:
sudo systemctl status httpd
The final result should resemble this:
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2022-12-1 15:24:58 UTC; 6s ago
Adjusting the Firewall
On Centos 8, FirewallD is the pre-installed firewall program.
Apache creates firewalld service files with pre-set rules for allowing access to HTTP (80) and HTTPS (443) ports during installation.
The required ports will be permanently opened by the following commands:
sudo firewall-cmd --permanent --zone=public --add-service=httpsudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
What follows is a detailed breakdown of the Apache configuration file structure, as well as recommendations for optimal administration of the Apache web server.
/etc/httpd directory houses all of Apache’s configuration files.
The httpd.conf file in the
/etc/httpd/conf directory is where Apache’s primary settings are stored.
The main Apache configuration file incorporates all.conf-ending configuration files in the
/etc/httpd/conf.modules.d folder contains configuration files used to load specific Apache modules.
Each Apache vhost file must have a.conf extension and live in the /etc/httpd/conf.d folder. Create as many virtual hosts as you like. When you make a virtual host (vhost) for each domain, you reduce the server’s administration burden.
Establishing and sticking to a consistent naming convention is a good idea. As an illustration, if the domain is mydomain.com, the corresponding configuration file should also be named mydomain.com. conf Apache log files (access log and error log) are located in the
/var/log/httpd/ directory. In order to keep track of what went wrong in each vhost, it’s best to keep the access and error logs separate.
You’re free to choose any directory you like as the root directory of your domain. Webroot is most frequently used in the following places:
Your CentOS 8 server now has Apache installed successfully. Now that you’re prepared, you can use Apache as a web or proxy server to begin deploying your applications.
Similar to how you manage other systemd units, you can manage the Apache service.
Please leave a comment if you have any queries or suggestions.