How to Install the Mod Security Apache Module on CentOS / RedHat (RHEL)

Install the ModSecurity Apache Module on CentOS alma linux RHEL red hat

ModSecurity is an open-source web application firewall (WAF) that helps to protect your web applications from various types of attacks. It can be integrated with the Apache web server as a module to provide additional security for your website. In this tutorial, we will show you how to install the ModSecurity Apache module on a CentOS server running Apache.


Before you begin, you will need the following:

  • A CentOS / RedHat (RHEL) server running Apache
  • Root access to the server

Step 1: Install Required Dependencies

To install ModSecurity, you will need to install some dependencies. You can install them by running the following command:

$ sudo yum install -y mod_security

Step 2: Enable the ModSecurity Apache Module

To enable the ModSecurity Apache module, you will need to run the following command:

$ sudo ln -s /etc/httpd/conf.d/mod_security.conf /etc/httpd/conf.modules.d/00-mod_security.conf

This command will enable the mod_security module for Apache.

Step 3: Configure Apache to Use the ModSecurity Apache Module

Once the module is installed, you will need to configure Apache to use it. To do this, you will need to edit the Apache configuration file (usually located at /etc/httpd/conf.d/mod_security.conf).

You can make any changes you want to the module’s configuration in this file.

Step 4: Restart Apache

Finally, you need to restart Apache for the changes to take effect.

$ sudo systemctl restart httpd

Now, the ModSecurity Apache module should be installed and configured on your CentOS server. You can check if the module is working by looking at the Apache error log (usually located at /var/log/httpd/error_log) or by running httpd -M command.

You can also check the default rules that come with the module in the directory /usr/share/modsecurity-crs/ and configure it to your liking.