The Apache HTTP server is the most widely used web server in the world. It is a free, open source, and cross-platform HTTP server that contains powerful features and can be extended with many modules.
In this article, we will explain how to install and manage Apache web server on CentOS 8.
Apache is available in the default CentOS source repository and installation is very straightforward.
In RHEL-based distributions, Apache packages and services are called httpd
. To install Apache, use root or another user with sudo privileges and run the following command:
sudo yum install httpd
Once the installation is complete, enable and start the Apache service:
sudo systemctl enable httpd
sudo systemctl start httpd
To verify that the service is running, check its status:
sudo systemctl status httpd
The output looks 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-1215:54:58 UTC; 6s ago
...
FirewallD is the default firewall scheme on CentOS 8.
During the installation process, Apache created a firewalld service file using predetermined rules to allow access to HTTP (80) and HTTPS (443) ports.
The following command 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 --reload
This section explains how Apache configuration files are organized and the best practices for managing Apache web servers.
All Apache configuration files are in the /etc/httpd
directory
The main Apache configuration file is: /etc/httpd/conf/httpd.conf
.
All configuration files ending with .conf
in the /etc/httpd
directory will be included in the main Apache configuration file.
Represents the configuration files that load various Apache modules, in the /etc/httpd/conf.modules.d
directory
The Apache vhost file must end with the .conf
file and be stored in the /etc/httpd/conf.d
directory. You can define as many vhosts as virtual hosts. It is easier to maintain a separate configuration (vhost) for each domain name.
Naming according to standards is a good practice. For example, if the domain name is mydomain.com
, then the configuration file should be named: mydomain.com.conf
Apache log files (access_log and error_log) are in the /var/log/httpd/
directory. The recommended way is to create separate access
and error
files for each virtual host (vhost).
You can set the root directory of your domain name document anywhere you want. The most common locations for the website root directory include:
/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
Congratulations, you have successfully installed Apache on your CentOS 8 system. You are ready to deploy your application and use Apache as a web server or proxy server.
Recommended Posts