Securing your WHMCS (Web Host Manager Complete Solution) installation on an Ubuntu server is crucial for protecting sensitive data and maintaining the integrity of your hosting environment. In this tutorial, we will walk through essential steps to harden your WHMCS Ubuntu server, ensuring it is secure from potential threats.

Thanks to Teklan Hosting

A big thank you to Teklan Hosting for providing us with a server. Their support has made it possible for us to create and share this guide with you.

We appreciate Teklan Hosting’s contribution to our project – Give them a look if you need a VPS, Web hosting, Domains or dedicated servers and much more!

Step 1: Update and Upgrade the System

Before diving into security configurations, ensure your server’s packages are up-to-date. This reduces the risk of vulnerabilities in outdated software.

sudo apt update && sudo apt upgrade -y

Step 2: Configure the Firewall

A properly configured firewall is the first line of defence against unwanted traffic. UFW (Uncomplicated Firewall) is a user-friendly interface for managing firewall rules.

sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable

Step 3: Secure SSH
To prevent unauthorised access via SSH, follow these best practices:

1. Disable Root Login: Edit the SSH configuration file.

sudo nano /etc/ssh/sshd_config

Locate the PermitRootLogin directive and set it to no.

PermitRootLogin no

2. Change the Default SSH Port: Modify the Port directive to a non-standard port.

Port 6969

3. Use SSH Key Authentication: Generate SSH keys and disable password authentication.

ssh-keygen -t rsa -b 4096
ssh-copy-id user@server_ip

Edit the SSH configuration file again:

sudo nano /etc/ssh/sshd_config

Set PasswordAuthentication to no.

PasswordAuthentication no

Restart the SSH service:

sudo systemctl restart ssh

Step 4: Install Fail2Ban

Fail2Ban helps protect your server from brute-force attacks by banning IPs that show malicious signs.

sudo apt install fail2ban

sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local

Ensure the SSH jail is enabled:

[sshd]
enabled = true

Start and enable Fail2Ban:

sudo systemctl start fail2ban
sudo systemctl enable fail2ban


Step 5: Install and Configure ModSecurity
ModSecurity is a web application firewall (WAF) for Apache, providing protection against various attacks.


sudo apt install libapache2-mod-security2
sudo a2enmod security2

Download the OWASP ModSecurity Core Rule Set (CRS):

sudo apt install modsecurity-crs
sudo mv /usr/share/modsecurity-crs /etc/modsecurity/crs
sudo cp /etc/modsecurity/crs/crs-setup.conf.example /etc/modsecurity/crs/crs-setup.conf

Edit the ModSecurity configuration:

sudo nano /etc/modsecurity/modsecurity.conf

Set SecRuleEngine to On.

SecRuleEngine On
sudo systemctl restart apache2

Step 6: Secure MySQL
Securing your MySQL installation is essential for protecting your WHMCS data.

sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove test databases, and reload privilege tables.


Step 7: Enable HTTPS
Encrypting traffic between your server and clients is crucial. Use Let’s Encrypt to obtain a free SSL certificate.

1. Install Certbot:

sudo apt install certbot python3-certbot-apache

2. Obtain and Install the Certificate:

sudo certbot --apache

Follow the prompts to complete the installation. Certbot will configure your Apache virtual host files to use the SSL certificate.


Step 8: Regular Backups
Ensure you have regular backups of your WHMCS installation and databases. Use tools like rsync, tar, or specialised backup solutions to automate this process.


Step 9: Monitor and Audit
Regularly monitor and audit your server for suspicious activity. Tools like Logwatch and OSSEC can help with this.

sudo apt install logwatch
sudo nano /etc/cron.daily/00logwatch

Set the following configuration:

#!/bin/sh
/usr/sbin/logwatch --output mail --mailto your-email@example.com --detail high

Conclusion

Hardening your WHMCS Ubuntu server involves multiple layers of security, from basic system updates to configuring firewalls, securing SSH, and installing additional security tools. Regular monitoring and maintenance are crucial to ensure your server remains secure. By following these steps, you can significantly reduce the risk of security breaches and protect your WHMCS installation.

Feel free to leave any comments or questions below. Happy hosting!

By Tech Tutorial

Hey, I'm Chris! Nerd, Business owner, Serial Procrastinator! Will add more info soon :)