How To Install mod_security on CentOS 8

mod_security is Security module for the Apache HTTP Server

Introduction

In this tutorial we learn how to install mod_security on CentOS 8.

What is mod_security

ModSecurity is an open source intrusion detection and prevention engine for web applications. It operates embedded into the web server, acting as a powerful umbrella - shielding web applications from attacks.

We can use yum or dnf to install mod_security on CentOS 8. In this tutorial we discuss both methods but you only need to choose one of method to install mod_security.

Install mod_security on CentOS 8 Using dnf

Update yum database with dnf using the following command.

sudo dnf makecache --refresh

The output should look something like this:

CentOS Linux 8 - AppStream                                       43 kB/s | 4.3 kB     00:00    
CentOS Linux 8 - BaseOS                                          65 kB/s | 3.9 kB     00:00    
CentOS Linux 8 - ContinuousRelease                               43 kB/s | 3.0 kB     00:00    
CentOS Linux 8 - Extras                                          23 kB/s | 1.5 kB     00:00    
CentOS Linux 8 - FastTrack                                       40 kB/s | 3.0 kB     00:00    
CentOS Linux 8 - HighAvailability                                36 kB/s | 3.9 kB     00:00    
CentOS Linux 8 - Plus                                            24 kB/s | 1.5 kB     00:00    
CentOS Linux 8 - PowerTools                                      50 kB/s | 4.3 kB     00:00    
Extra Packages for Enterprise Linux Modular 8 - x86_64           13 kB/s | 9.2 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                   24 kB/s | 8.5 kB     00:00    
Metadata cache created.

After updating yum database, We can install mod_security using dnf by running the following command:

sudo dnf -y install mod_security

Install mod_security on CentOS 8 Using yum

Update yum database with yum using the following command.

sudo yum makecache --refresh

The output should look something like this:

CentOS Linux 8 - AppStream                                       43 kB/s | 4.3 kB     00:00    
CentOS Linux 8 - BaseOS                                          65 kB/s | 3.9 kB     00:00    
CentOS Linux 8 - ContinuousRelease                               43 kB/s | 3.0 kB     00:00    
CentOS Linux 8 - Extras                                          23 kB/s | 1.5 kB     00:00    
CentOS Linux 8 - FastTrack                                       40 kB/s | 3.0 kB     00:00    
CentOS Linux 8 - HighAvailability                                36 kB/s | 3.9 kB     00:00    
CentOS Linux 8 - Plus                                            24 kB/s | 1.5 kB     00:00    
CentOS Linux 8 - PowerTools                                      50 kB/s | 4.3 kB     00:00    
Extra Packages for Enterprise Linux Modular 8 - x86_64           13 kB/s | 9.2 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                   24 kB/s | 8.5 kB     00:00    
Metadata cache created.

After updating yum database, We can install mod_security using yum by running the following command:

sudo yum -y install mod_security

How To Uninstall mod_security on CentOS 8

To uninstall only the mod_security package we can use the following command:

sudo dnf remove mod_security

mod_security Package Contents on CentOS 8

/etc/httpd/conf.d/mod_security.conf
/etc/httpd/conf.modules.d/10-mod_security.conf
/etc/httpd/modsecurity.d
/etc/httpd/modsecurity.d/activated_rules
/etc/httpd/modsecurity.d/local_rules
/etc/httpd/modsecurity.d/local_rules/modsecurity_localrules.conf
/usr/lib/.build-id
/usr/lib/.build-id/aa
/usr/lib/.build-id/aa/952a5e91e02a91ceda8a330d0a427b37e4510b
/usr/lib64/httpd/modules/mod_security2.so
/usr/share/doc/mod_security
/usr/share/doc/mod_security/CHANGES
/usr/share/doc/mod_security/LICENSE
/usr/share/doc/mod_security/NOTICE
/usr/share/doc/mod_security/README.TXT
/var/lib/mod_security

References

Summary

In this tutorial we learn how to install mod_security on CentOS 8 using yum and dnf.