Secure & Optimise a cPanel Server guide, updated for modern best practices, current WHM/cPanel versions (e.g., 126+), and modern Linux distros (e.g., AlmaLinux 9/CloudLinux 9):
β οΈ Disclaimer: This is a general guide, not a guarantee. Use at your own risk. If in doubt, consult a professional system administrator.
β Keep All Software Updated
Update via WHM:
- WHM Β» cPanel Β» Upgrade to Latest Version
- WHM Β» Software Β» EasyApache 4
- WHM Β» System Update (for OS packages)
Command line update:
dnf update -y && dnf upgrade -y
βοΈ Tweak Settings (WHM)
WHM Β» Server Configuration Β» Tweak Settings
Setting | Recommended Value |
---|---|
Require SSL | On |
Allow Remote Domains | On |
Allow unregistered domains | On |
Hide login password from CGI scripts | On |
Conserve memory | Off |
Enable SPF on domains for new accounts | On |
Default catch-all forwarder destination | Fail |
Track email origin via X-Source headers | On |
Use pigz for compression | On |
Use jailshell by default | Off |
Prevent βnobodyβ from sending mail | On |
Critical load threshold | Autodetect |
PHP max POST size (UI) | 155M |
PHP max upload size (UI) | 100M |
Enable BoxTrapper | Off |
PHP loader | ionCube |
Set timezone | Europe/London |
π Secure cPanel & WHM Settings
Security Center:
- β
Enable
php open_basedir Protection
- β
Enable
mod_userdir Protection
- β
Enable
Shell Fork Bomb/Memory Protection
- β Disable compilers (except root)
- β
Enable
cPHulk Brute Force Protection
- β Remove all users from Wheel Group (except root and your main admin)
- β Run Quick Security Scan
- β Enable Background Process Killer
- β Disable Shell Access for all accounts (except root/main)
- β
Disable Anonymous FTP (
WHM Β» FTP Configuration
) - β
Change MySQL root password (
WHM Β» SQL Services
) - β
Apache:
- ServerSignature:
Off
- ServerTokens:
ProductOnly
- ServerSignature:
π§Ύ Set SSH Legal Login Banner
nano /etc/motd
Example:
ALERT! You are entering a secured area. Your IP and login have been logged.
Unauthorized access is prohibited and will be reported.
Save and exit: CTRL+X β Y β Enter
π SSH Hardening (AlmaLinux 9 / CloudLinux 9)
Edit the SSH config:
nano /etc/ssh/sshd_config
Recommended changes:
Port 5678 # use a non-standard port
Protocol 2
PermitRootLogin no # use sudo instead
PasswordAuthentication no # use SSH keys
UseDNS no
Restart SSH:
systemctl restart sshd
Open SSH port in firewall:
firewall-cmd --permanent --add-port=5678/tcp
firewall-cmd --reload
π PHP Configuration
Via WHM Β» MultiPHP INI Editor or edit php.ini
:
memory_limit = 512M
max_execution_time = 300
max_input_time = -1
upload_max_filesize = 100M
post_max_size = 100M
enable_dl = Off
disable_functions = system, exec, shell_exec
π§± EasyApache 4 Profile
Use: All PHP Options + OpCache
Enable extensions: ionCube
, OPcache
, imagick
, zip
, intl
, etc.
π₯ Install and Configure CSF (ConfigServer Security & Firewall)
dnf install perl-libwww-perl perl-LWP-Protocol-https -y
rm -fv csf.tgz
wget https://download.configserver.com/csf.tgz
tar -xzf csf.tgz
cd csf
sh install.sh
Initial CSF Settings:
TESTING = 0
RESTRICT_SYSLOG = 2
SMTP_BLOCK = 1
TCP_IN = 20,21,22,28,53,80,110,143,443,465,587,993,995,2077-2096,30000:35000
Optional performance adjustments:
LF_EMAIL_ALERT = 0
LF_DIRWATCH = 0
LF_INTEGRITY = 0
CT_EMAIL_ALERT = 0
PT_LIMIT = 0
PS_EMAIL_ALERT = 0
π Passive FTP Fix (Pure-FTPd)
If passive FTP fails, set:
nano /etc/pure-ftpd.conf
Add:
PassivePortRange 30000 35000
Restart:
systemctl restart pure-ftpd
And ensure ports are open in CSF:
TCP_IN = 30000:35000
π« Disable Telnet (if present)
nano /etc/xinetd.d/telnet
Set:
disable = yes
Then:
systemctl restart xinetd
systemctl stop xinetd
Also block via /etc/hosts.deny
:
echo "in.telnetd : ALL : severity emerg" >> /etc/hosts.deny
π§ Bonus Tips
- β Enable Imunify360 for AI-powered security
- β Enable KernelCare for rebootless kernel updates
- β Install ClamAV if you’re hosting email accounts
- β Limit PHP versions to supported releases (e.g., 8.1, 8.2, 8.3)
- β Regularly audit accounts & installed plugins