Would you like to learn how to install the Apache Modsecurity feature?  In this tutorial, we are going to configure the Apache's Modsecurity feature on a computer running Ubuntu Linux.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Apache 2.4.41
• ModSecurity 3.0.4

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Apache - ModSecurity installation

Install the Apache server.

Copy to Clipboard

Install the required packages.

Copy to Clipboard

Install the software named SSDEP.

Copy to Clipboard

Download the latest version of ModSecurity.

Copy to Clipboard

Compile and install ModSecurity.

Copy to Clipboard

Download the latest version of the Apache connector for ModSecurity.

Copy to Clipboard

Compile and install the Apache connector.

Copy to Clipboard

Download and install the ModSecurity Core Rule Set.

Copy to Clipboard

Congratulations! You have finished the ModSecurity installation on the Apache server.

Tutorial Apache - ModSecurity configuration

Create a file to enable the use of ModSecurity.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Create a directory named Modsec and copy the required configuration files.

Copy to Clipboard

Edit the ModSecurity configuration file.

Copy to Clipboard

Locate the following lines.

Copy to Clipboard

Change these lines to the following configuration.

Copy to Clipboard

Here is the file after our configuration.

Copy to Clipboard

Create a file to enable ModSecurity to use the installed CRS rules.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

Verify if the Apache module named Security3_module was loaded.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Optionally, use your browser to send a test request to the Apache server.

After sending a test request, verify the ModSecurity log

Copy to Clipboard

Congratulations! You have finished the ModSecurity configuration on the Apache server.