Skip to content

Per-vhost custom Apache error logs on cPanel without losing cPanel's defaults

How to add a custom Apache error log for a single vhost on cPanel through the Include Editor so logrotate and cPanel's userdata cache do not undo the change.

A developer asks for a separate Apache error log on one domain so a noisy plugin’s stack traces can be tailed without scrolling through eight other sites. On cPanel, dropping the ErrorLog directive into httpd.conf directly does not survive /scripts/rebuildhttpdconf. The supported path is the WHM Include Editor — a tiny detail that makes the difference between a five-minute change and a Monday morning of “where did my log go.”

What’s happening

cPanel regenerates /etc/apache2/conf/httpd.conf from /var/cpanel/userdata/ every time a vhost changes, the server reboots, EasyApache provisions, or /scripts/rebuildhttpdconf runs. The Include Editor in WHM is the supported place to inject extra Apache directives, scoped to either the global config, a virtual host, or a specific PHP version. Anything in there is preserved through cPanel’s regeneration cycle.

How to verify

Confirm the current logging setup for the vhost:

whmapi1 fetch_vhost_includes domain=example.com
grep -r "ErrorLog" /etc/apache2/conf.d/userdata/ | grep example.com
ls -la /usr/local/apache/logs/
apachectl -t -D DUMP_VHOSTS | grep example.com

The first command lists includes already registered for the domain. The grep shows whether the domain already has a custom error log set via the supported channel.

The fix

  1. WHM > Apache Configuration > Include Editor > Post VirtualHost Include > select the appropriate Apache version > pick the vhost. Paste:
    ErrorLog /var/log/apache2/example.com-error.log
    LogLevel warn
  2. Click Update. cPanel writes the snippet under /etc/apache2/conf.d/userdata/std/2_4/<user>/<domain>/. This file is preserved across regenerations.
  3. Pre-create the log file and directory with safe ownership: mkdir -p /var/log/apache2 && touch /var/log/apache2/example.com-error.log && chown root:root /var/log/apache2/example.com-error.log && chmod 644 /var/log/apache2/example.com-error.log. Do not put the log inside the customer’s /home/<user>/ tree — logrotate config and ownership get awkward.
  4. Add the new path to logrotate: drop a file at /etc/logrotate.d/apache2-custom with the standard cPanel-style rotation (daily, rotate 14, compress, sharedscripts, postrotate /usr/sbin/apachectl graceful).
  5. apachectl -t && apachectl graceful. Confirm the new log file is being written to during a synthetic request. Confirm /usr/local/apache/logs/error_log still receives global errors — you have not redirected them all, only the ones from this vhost.
  6. Document the path. The next operator who tails error_log and sees nothing will thank you.

For environments where per-vhost logging needs to be standard, Stack Harbor sets this up alongside log shipping as part of cPanel/WHM management.