How to disable server's mod_security?

Introduction

mod_security is an apache module that helps to protect your website from various attacks. It is used to block commonly known exploits by use of regular expressions and rule sets and is enabled on some providers' servers by default.

In LaraClassifier and JobClass case, since PHP functions like exec() and escapeshellarg() need to be enabled to make work them, depending on the hosting provider, you have to disable the mod_security to avoid errors 403 or reCAPTCHA protections for static files.

From cPanel

To disable the mod_security from cPanel, login to cPanel, under the Security section, click on ModSecurity.

On next page, you can see the list of domains and on/off status. ModSecurity will be ON by default for all your sites. Click on OFF button to disable ModSecurity

From .htaccess

If for some reasons, you are not able to disable the mod_security from your cPanel, you can do that in the main .htaccess file with the code below:

<IfModule mod_security.c>
    SecFilterEngine Off
    SecFilterScanPOST Off
</IfModule>

Note that mod_security coud be compiled to prevent this switch off by .htaccess files. And the host could also limit .htaccess authorizations via AllowOverride settings.

On some servers and web hosts, it's possible to disable ModSecurity via .htaccess, but be aware that you can only switch it on or off, you can't disable individual rules.

But a good practice that still keeps your site secure is to disable it only on specific URLs, rather than your entire site. You can specify which URLs to match via the regex in the <If> statement below...

### DISABLE mod_security firewall
### Some rules are currently too strict and are blocking legitimate users
### We only disable it for URLs that contain the regex below
### The regex below should be placed between "m#" and "#"
### (this syntax is required when the string contains forward slashes)
<IfModule mod_security.c>
    <If "%{REQUEST_URI} =~ m#/assets/#">
        SecFilterEngine Off
        SecFilterScanPOST Off
    </If>
</IfModule>

References: