In this guide, we are going to learn how to install and configure LibModsecurity with Apache on CentOS 8. LibMosecurity also known as ModSecurity version 3, is an open source, cross platform web application firewall (WAF) engine which provides protection against a wide range of web application attacks.

With the following directions, you will know how to install and configure LibModsecurity with Apache on CentOS 8!

Configure LibModsecurity with Apache on CentOS 8

Run System Update

Begin by updating your system packages.

dnf update

Install Required Build Tools and Dependencies

LibModsecurity are going to be compiled from the source and thus a number of build tools and dependencies are required. Run the command below to install them.

dnf config-manager --set-enabled powertools

Install additional repositories.

dnf install
dnf install
dnf config-manager --set-enabled remi

Install the required dependencies.

dnf install gcc-c++ flex bison yajl curl-devel curl zlib-devel pcre-devel autoconf automake git curl make libxml2-devel pkgconfig libtool httpd-devel redhat-rpm-config git wget openssl openssl-devel vim GeoIP-devel doxygen yajl-devel libmaxminddb libmaxminddb-devel GeoIP-devel lmdb lmdb-devel ssdeep-devel lua-devel

Download LibModsecurity Source Code

Create a temporary directory to store the source tarballs.

mkdir ~/modsec

You can choose to use /opt instead.

Navigate to ModSecurity releases page and download ModSecurity source code. You can simply use wget to pull it.

cd ~/modsec
wget -P ~/modsec

Extract the ModSecurity source code.

cd ~/modsec
tar xzf modsecurity-v3.0.4.tar.gz

Compile and Install LibModsecurity

Navigate to the LibModsecurity source directory, configure, compile and install it

cd modsecurity-v3.0.4

Configure LibModsecurity to adapt it to your system and check if any required dependency is missing.


You can safely ignore the fatal: No names found, cannot describe anything messages.


Fix any dependency issue just in case there is any before you can proceed to compile and install LibModsecurity with Apache on CentOS

Compile and install LibModSecurity.

make install

Install ModSecurity-Apache Connector on CentOS 8

Once the installation of LibModsecurity is done, proceed to install the ModSecurity-apache connector which provides a communication channel between Apache and libModsecurity.

Clone the git repository for the ModSecurity Apache connector.

cd ~
git clone

Navigate to ModSecurity-apache directory and run the following commands to compile and install it.

cd ModSecurity-apache
./configure --with-libmodsecurity=/usr/local/modsecurity/
make install

Configure Apache with LibModsecurity on CentOS 8

Next, configure Apache to load Modsecurity Apache connector module by adding the line below to the main Apache configuration file.

echo "LoadModule security3_module /usr/lib64/httpd/modules/" | sudo tee -a /etc/httpd/conf/httpd.conf

Create ModSecurity configuration directory under /etc/httpd/conf.d

mkdir /etc/httpd/conf.d/modsecurity.d

Copy the sample ModSecurity configuration file from the source code directory to the ModSec configuration directory created above renaming it as follows.

cp ~/modsec/modsecurity-v3.0.4/modsecurity.conf-recommended /etc/httpd/conf.d/modsecurity.d/modsecurity.conf

Also copy the unicode.mapping file from ModSecurity source directory to Apache Modsecurity configuration directory.

sudo cp ~/modsec/modsecurity-v3.0.4/unicode.mapping /etc/httpd/conf.d/modsecurity.d/

Activate ModSecurity by changing the value of SecRuleEngine to On.

sed -i 's/SecRuleEngine DetectionOnly/SecRuleEngine On/' /etc/httpd/conf.d/modsecurity.d/modsecurity.conf

Change the default log directory for Modsecurity

sed -i 's#/var/log/modsec_audit.log#/var/log/httpd/modsec_audit.log#' /etc/httpd/conf.d/modsecurity.d/modsecurity.conf

Configure ModSecurity rules by creating a file where you can define the rules to include.

vim /etc/httpd/conf.d/modsecurity.d/rules.conf
Include "/etc/httpd/conf.d/modsecurity.d/modsecurity.conf"
Include "/etc/httpd/conf.d/modsecurity.d/owasp-crs/crs-setup.conf"
Include "/etc/httpd/conf.d/modsecurity.d/owasp-crs/rules/*.conf"

Since we have included the OWASP Rules, proceed to install them.

Install OWASP ModSecurity Core Rule Set (CRS)

The OWASP ModSecurity Core Rule Set (CRS) is a set of generic attack detection rules for use with ModSecurity. It aims at protecting the web applications from a wide range of attacks, including the OWASP Top Ten, minimum of false alerts.

Clone the CRS from GitHub repository to /etc/apache2/modsecurity.d/ as shown below;

git clone /etc/httpd/conf.d/modsecurity.d/owasp-crs

Next, rename crs-setup.conf.example to crs-setup.conf.

cp /etc/httpd/conf.d/modsecurity.d/owasp-crs/crs-setup.conf{.example,}

Activate ModSecurity 3 on CentOS 8

After all that, activate the modsecurity on the default site configuration file or on any virtual host configuration file. In this guide, we are using Apache’s default site configuration file.

Note that you have to enable ModSecurity per directory context.

vim /etc/httpd/conf/httpd.conf

See our below the changes made on the default web root directory on the default Apache configuration;

<Directory "/var/www/html">
    modsecurity on
    modsecurity_rules_file /etc/httpd/conf.d/modsecurity.d/rules.conf
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

The lines;

 modsecurity on
 modsecurity_rules_file /etc/httpd/conf.d/modsecurity.d/rules.conf

Turns on Modsecurity and specifies the location of the Modsecurity rules respectively.

Check Apache for configuration errors and restart it.

httpd -t
Syntax OK
systemctl restart httpd

Testing Modsecurity

Next, test the effectiveness of Modsecurity with OWASP rules, for example, using the command injection. Run the command below;

curl localhost/index.html?exec=/bin/bash
<title>403 Forbidden</title>
<p>You don't have permission to access /index.html
on this server.</p>

If you see, 403 Forbidden then it means you have nailed it.

You can as well check Modsecurity logs;

tail /var/log/httpd/modsec_audit.log
ModSecurity: Warning. Matched "Operator `PmFromFile' with parameter `' against variable `ARGS:exec' (Value: `/bin/bash' ) [file "/etc/httpd/conf.d/modsecurity.d/owasp-crs/rules/REQUEST-932-APPLICATION-ATTACK-RCE.conf"] [line "496"] [id "932160"] [rev ""] [msg "Remote Command Execution: Unix Shell Code Found"] [data "Matched Data: bin/bash found within ARGS:exec: /bin/bash"] [severity "2"] [ver "OWASP_CRS/3.2.0"] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-shell"] [tag "platform-unix"] [tag "attack-rce"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "OWASP_CRS/WEB_ATTACK/COMMAND_INJECTION"] [tag "WASCTC/WASC-31"] [tag "OWASP_TOP_10/A1"] [tag "PCI/6.5.2"] [hostname ""] [uri "/index.html"] [unique_id "158386776469.002836"] [ref "o1,8v21,9t:urlDecodeUni,t:cmdLine,t:normalizePath,t:lowercase"]
ModSecurity: Access denied with code 403 (phase 2). Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' ) [file "/etc/httpd/conf.d/modsecurity.d/owasp-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "79"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [data ""] [severity "2"] [ver ""] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname ""] [uri "/index.html"] [unique_id "158386776469.002836"] [ref ""]

Well, there you go. ModSecurity 3 or LibModSeceurity is now installed, activated and protecting your site against web attacks.

Feel free to set up more rules as you wish and protect your web application.

That marks the end of our our guide on how to install and configure LibModsecurity with Apache on CentOS 8.

5.0 from 10 reviews
Ratings and reviews
  • 5.0 from 10 reviews

    The only hosting provider I trust with my VPS

  • SiteCheck Admin

  • ArticleSurge Editor (

    Very reliable and more helpful than big host companies I've used previously. Very glad to have discovered it about three years ago. I hope they continue to be supportive. The prices are good because they do not have increased renewal fees like almost everyone else.


    The only hosting provider I trust with my VPS

  • SiteCheck Admin

  • Artist Of

    As kindly as I can say: got some really bad spam from these people and did a search and found this web hoster as a provider of them at the time. I am hoping this complaint will further facilitate ending this, spam harassment.I must update this review. I finally conquered this problem sometimes you just have to comp[lain enough about some things. Stay radical Rad Web.

  • Todd Greenwald

    We're a single server company that manages our box ourselves. We had to move to a new NOC in a pinch and we chose Rad Web Hosting. They were thorough and complete in the phase of learning their capabilities (their chat access is excellent), and they delivered 100% in what they said they offered. We had a new server shipped to them from Dell, they installed and provisioned immediately and turned the machine over to us ready to go with both IDRAC via VPN and Internet availability. Whenever we have had questions they have been thorough and prompt. In our >20 years of business, this is by far the best NOC we've been in.


    Very great hosting and servers. Have used for years and plan to continue on! Thanks Rad Web Hosting!

  • Bitcoin Linux

    Great service and support after the sale. I much like the renewal price is the same as the price I signed up with. No surprises and no games!

  • SiteCheck Admin

    Excellent hosting service all the way through! From the helpful staff to their consistent performance and affordability. So much better than the big guys!

Avatar of editorial staff

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX and Phoenix, AZ.