Skip to content

Log rotation and disk pressure on cPanel hosts

Find and fix the log files that fill the disk on a cPanel server when log rotation stops working. Check which logs are growing, confirm logrotate covers each one, trim the ModSecurity audit log, and add a disk alert before /var runs out of space.

If /var on your cPanel server keeps filling up, a log file that never gets rotated is the usual cause. Log rotation is the routine job, run by logrotate and by cPanel’s own cpanellogd, that renames, compresses and eventually deletes old logs so they cannot grow forever. When it skips a file, that file can reach gigabytes, and the ModSecurity audit log (the web application firewall’s record of flagged requests) can grow by hundreds of MB a day on a site under attack. Once /var is full, MySQL crashes, mail queues stall and the server stops accepting new sessions. Find the largest logs, confirm each one has a rotation rule, trim what ModSecurity records, and add a disk alert so you hear about it before your users do.

What’s happening

cPanel ships its own log management for many of its logs (cpanellogd, log archiving), but several logs are managed by logrotate.d configs that come from the underlying package (Apache, exim, fail2ban, etc). When custom configs override defaults, or when a daemon reopens its log on a non-rotation-aware schedule, the file grows without bound. ModSec audit logs are the worst because they include the entire request body for every transaction flagged by a rule — easily 50 KB per transaction, hundreds per minute on a public-facing site.

The secondary problem: even when rotation runs, retention is sometimes set to “keep 52 weekly archives” by default. A year of access logs on a busy site is gigabytes. Cleanup needs to run too.

How to verify

Find the largest files in /var/log and related locations:

du -h /var/log /usr/local/apache/logs /var/cpanel/logs 2>/dev/null | sort -h | tail -20
find /var/log /usr/local/apache/logs -type f -size +500M
df -h /var

For specific logs, check whether logrotate has them in scope:

ls /etc/logrotate.d/
grep -l modsec /etc/logrotate.d/*
grep -l 'apache' /etc/logrotate.d/*
logrotate -d /etc/logrotate.conf 2>&1 | head -50

The -d flag does a dry run and prints what logrotate thinks it should do, without actually rotating. Files that should rotate but do not show up in the dry run are the gap.

The fix

  1. Confirm logrotate.d coverage for Apache, modsec, exim, cpanel logs, and any custom application logs. Each needs a stanza with rotate N, daily or weekly, compress, delaycompress, notifempty, and either copytruncate or a postrotate script that signals the daemon.
  2. ModSec audit specifically — set SecAuditLogParts ABEFHKZ (drop the J content body when not strictly needed) and consider sampling with SecAuditEngine RelevantOnly plus a tight status-code regex.
  3. Apache access logs per vhost — cPanel’s domlogs rotation runs nightly via cpanellogd; verify the config in WHM > Server Configuration > Statistics Software. Default retention is 30 days; tune if disk is tight.
  4. Exim — /etc/cron.daily/exim_tidydb and the logrotate config keep mail logs from growing forever. If exim_mainlog is over 5 GB, the rotation has been broken for weeks.
  5. Add disk monitoring — df -h /var over 80% should fire an alert, not a customer ticket. Without monitoring, log overflow is a midnight emergency.

After fixing, force a rotation: logrotate -f /etc/logrotate.conf. Then verify disk recovers and the affected daemons keep writing to new log files. Stack Harbor manages log rotation and disk monitoring as part of WHM server management.