Introduction
Apache is one of the most widely used web servers globally. ModSecurity is an open-source web application firewall that provides enhanced security by protecting web applications from attacks. This guide will walk you through the installation of Apache with ModSecurity on Ubuntu 22.04, an ideal setup for environments hosted on a Windows VPS UK.
Prerequisites
- An Ubuntu 22.04 server with root access
- Basic knowledge of Linux commands
- An active internet connection
Step 1: Update Your System
Start by updating your package index and upgrading existing packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache
Install the Apache web server using the following command:
sudo apt install apache2 -y
Enable and start the Apache service:
sudo systemctl enable apache2
sudo systemctl start apache2
Step 3: Install ModSecurity
To install ModSecurity, first, install the required dependencies:
sudo apt install libapache2-mod-security2 -y
After installation, enable ModSecurity:
sudo a2enmod security2
Step 4: Configure ModSecurity
Copy the default configuration file:
sudo cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
Edit the configuration file to enable ModSecurity:
sudo nano /etc/modsecurity/modsecurity.conf
Change the line SecRuleEngine DetectionOnly
to SecRuleEngine On
.
Step 5: Download the OWASP Core Rule Set
Download and install the OWASP Core Rule Set (CRS) to enhance ModSecurity's protection:
wget https://github.com/coreruleset/coreruleset/archive/refs/heads/master.zip
unzip master.zip
sudo mv coreruleset-master /etc/modsecurity/owasp-crs
Step 6: Configure ModSecurity to Use the OWASP CRS
Create a new configuration file for the OWASP CRS:
sudo nano /etc/modsecurity/modsecurity.conf
Add the following lines to include the CRS:
Include /etc/modsecurity/owasp-crs/crs-setup.conf
Include /etc/modsecurity/owasp-crs/rules/*.conf
Step 7: Restart Apache
Restart the Apache server to apply the changes:
sudo systemctl restart apache2
Step 8: Verify Installation
To verify that ModSecurity is installed correctly, you can check the Apache error log:
sudo tail -f /var/log/apache2/error.log
You should see messages indicating that ModSecurity is loaded.
Step 9: Conclusion
You have successfully installed Apache with ModSecurity on Ubuntu 22.04. This enhanced web server security can significantly benefit from being hosted on a Windows VPS. For additional options, explore various VPS UK Windows solutions, including Windows Virtual Private Server Hosting and Windows VPS Hosting UK for optimal performance and security.