Skip to content

Apache log rotation on cPanel when disk pressure hits

How cPanel rotates Apache and per-domain logs by default, why the defaults often miss the disk-pressure case, and how to add aggressive compression and shorter retention without breaking AWStats.

cPanel rotates Apache logs nightly into /usr/local/apache/domlogs/<user>/<domain>.gz and the global error_log daily by logrotate. The defaults are tuned for an average shared host. On a busy server — single tenant pushing 50 GB of access log a day — the defaults are too slow: the previous day’s uncompressed log fills the disk before the rotation runs. Tweaking the rotation timing and compression is the difference between a clean inode count and an emergency disk cleanup at 3 AM.

What’s happening

Apache writes to error_log, access_log, and per-domain logs in /usr/local/apache/domlogs/. cPanel’s /etc/cpanel/logrotate.d/ config rotates these once a day. The intermediate uncompressed log file sits at full size for up to 24 hours before compression. On a 50 GB-of-logs-per-day account, that single uncompressed file alone is 50 GB. AWStats reads the rotated files to generate the customer-facing stats; aggressive deletion breaks the stats unless you keep at least a week of compressed data.

How to verify

See the current rotation state and disk pressure:

df -h /
df -h /var /usr/local/apache/logs
du -sh /usr/local/apache/domlogs/* | sort -h | tail
cat /etc/logrotate.d/httpd
cat /etc/cpanel/logrotate.d/cpanel-logs 2>/dev/null

The first three commands show where the pressure is. The last two show the current config.

The fix

  1. Drop a custom logrotate snippet at /etc/logrotate.d/apache2-cpanel-custom:
    /usr/local/apache/domlogs/*/*.log {
        hourly
        rotate 168  # 7 days of hourly = 168
        maxsize 1G
        compress
        compresscmd /usr/bin/zstd
        compressext .zst
        missingok
        notifempty
        sharedscripts
        postrotate
            /usr/sbin/apachectl graceful > /dev/null 2>/dev/null || true
        endscript
    }
    Hourly + maxsize 1G means a log file never grows past 1 GB before being compressed. zstd is significantly faster than gzip for the compression step, which matters when you are rotating every hour.
  2. Confirm logrotate is on an hourly schedule: cPanel’s default cron is daily. Add /etc/cron.hourly/logrotate-apache running /usr/sbin/logrotate /etc/logrotate.d/apache2-cpanel-custom.
  3. Validate: logrotate -d /etc/logrotate.d/apache2-cpanel-custom runs in debug mode without rotating. Confirm the matched files are what you expect.
  4. AWStats compatibility: cPanel’s AWStats configuration reads from /usr/local/apache/domlogs/. As long as you keep the previous day’s compressed files around, AWStats handles them transparently — it knows about .gz and (recent versions) .zst. Keep at least 48 hours of rotated logs to give AWStats time to run.
  5. Disable any other logrotate config that also rotates these files. Two configs writing to the same log path will duplicate or conflict.
  6. Monitor the rotation. find /usr/local/apache/domlogs -name '*.log' -mtime +1 should always be empty — any file older than a day is failed to rotate.

For environments where disk pressure on log volume is a recurring incident, Stack Harbor maintains hourly compressed rotation on busy hosts under WHM server management.