Apache is one of the most popular web server applications in the world. In this article, HOSTVN will guide you to install Apache on Centos 8.
Apache is one of the most popular web server applications in the world. In this article, HOSTVN will guide you to install Apache on Centos 8.
Instructions for installing Apache on Centos 8
1. Turn off SELinux
To turn off SELinux, use the following command
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config && setenforce 0
2. Install Apache on CentOS 8
2.1. Step 1: Install Apache
Apache is available in the CentOS repositories. You can install Apache with the command:
yum -y install httpd
Note:”httpd” is the name of the Apache service in CentOS.
2.2. Step 2: Manage Apache Web Server
To start the Apache service, use the following command:
systemctl start httpd
To configure Apache to start at system startup you can run the following command:
systemctl enable httpd
To check the status of the Apache service, use the following command:
systemctl status httpd
To reload Apache (Reload configuration files to apply changes) you can use the command:
systemctl reload httpd
Command to restart the entire Apache service:
systemctl restart httpd
To stop Apache use the command:
systemctl stop httpd
To disable Apache from starting, use the following command:
systemctl disable httpd
2.3. Step 3: Configure Firewalld
Firewalld allows blocking traffic on different ports. Each port has a number and different types of traffic use different ports. For your web server, you will need to allow HTTP and HTTPS traffic on ports 80 and 443 (respectively). If you are using Firewalld you will need to allow access to ports 80 and 443.
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https
Restart Firewalld for the configuration to take effect:
firewall-cmd --reload
Apache also provides ModSecurity, add-on modules that act as firewalls. You can install and configure ModSecurity as an extra layer of security, helping you monitor your traffic and prevent attacks through web vulnerabilities.
2.4. Step 4: Test Apache WebServer
In a terminal window, find your system IP address with the following commands:
hostname -I | awk '{print $1}'
If you are familiar with the commands IP a or ifconfigyou can use those commands instead.
Open a web browser and enter the IP address of the VPS. The system will display the Apache Default Page as shown in the image below:
2.5. Step 5: Apache Files and Folders
Apache is controlled by applying directives in the configuration files:
- /etc/httpd/conf/httpd.conf – Apache main configuration file
- /etc/httpd/ – Directory containing all configuration files
- /etc/httpd/conf.d/ – All configuration files in this directory will be included in the main configuration file
- /etc/httpd/conf.modules.d/ – Location for Apache modules configuration files
Note: When making configuration file changes, remember to always restart the Apache service to apply the new configuration.
Double check the Apache log files to monitor your web server:
- /var/log/httpd/ – Location of Apache log files
- /var/log/httpd/access_log – Display logs of accesses to the server
- /var/log/httpd/error_log – Displays a list of errors that Apache encounters
3. Reference link
4. Conclusion
Through this post HOSTVN guided you to install Apache on CentOS 8. If you have any suggestions, you can leave a comment below. In addition, you can see more instructions to install Nginx on CentOS 8.