Skip to content

Using Apache piped logs for a large busy vhost on cPanel

When and how to switch a high-traffic cPanel vhost from file-based logging to a piped log handler — for real-time processing, log shipping, or simply to stop the rotate-grace problem on large logs.

A single vhost on a cPanel server is writing 10 GB of access log a day. Logrotate runs nightly but the box runs out of inodes by 4 AM. The fix is not aggressive rotation — it is to stop writing the file at all on disk and instead pipe the log through a handler that ships it elsewhere or rotates in-stream. Apache’s piped log mechanism handles this; cPanel preserves the directive if you set it via the Include Editor.

What’s happening

CustomLog and ErrorLog can take either a filename or a pipe followed by a command. With a pipe, Apache forks the named program once at startup and writes log lines to its stdin. Standard handlers include rotatelogs (Apache’s own time-or-size-based rotator that compresses on the fly) and cronolog (older but still works). For a log-shipping setup, the pipe can be a vector or fluent-bit instance that forwards to a centralized log store.

How to verify

Confirm the current logging setup for the vhost:

apachectl -t -D DUMP_INCLUDES | grep -A3 example.com
grep -r "CustomLog\|ErrorLog\||" /etc/apache2/conf.d/userdata/std/2_4/<user>/<domain>/ 2>/dev/null
ls -la /usr/local/apache/domlogs/<user>/
which rotatelogs

If the vhost is using the default per-domain file, the include shows CustomLog "/usr/local/apache/domlogs/<user>/<domain>" combined.

The fix

  1. Confirm rotatelogs is available: which rotatelogs should return /usr/sbin/rotatelogs on most cPanel builds.
  2. WHM > Apache Configuration > Include Editor > Post VirtualHost Include > scope to the user’s vhost > add:
    CustomLog "|/usr/sbin/rotatelogs -L /var/log/apache2/example.com/current.log -p '/usr/local/cpanel/bin/post-rotate-compress.sh' /var/log/apache2/example.com/%Y/%m/%d/access.log 86400 -0" combined
    This writes to a daily-rotated file under /var/log/apache2/example.com/YYYY/MM/DD/access.log, keeps a current.log symlink, and runs a post-rotate hook to compress.
  3. Pre-create the directory tree and post-rotate-compress.sh:
    mkdir -p /var/log/apache2/example.com
    cat > /usr/local/cpanel/bin/post-rotate-compress.sh <<'EOF'
    #!/bin/bash
    zstd --rm "$1" &
    EOF
    chmod +x /usr/local/cpanel/bin/post-rotate-compress.sh
  4. apachectl -t && apachectl graceful. Confirm Apache forked the rotatelogs child: ps -ef | grep rotatelogs.
  5. Watch for an hour. current.log should be growing; the previous hour’s file should be compressed and renamed. If the symlink is not updating, the -L flag is being misinterpreted — check Apache’s version.
  6. AWStats integration: AWStats expects files in /usr/local/apache/domlogs/. If you move to piped logs, either point AWStats at the new path via WHM > Statistics Software Configuration, or run a nightly cron that copies the compressed files back to the cPanel-expected location for AWStats.

For environments where one or two vhosts dominate the log volume, Stack Harbor sets piped logging on those vhosts only as part of cPanel server management.