cPanel

How to Combine Apache Access Logs in cPanel

Access Logs
Combine Apache Access Logs

Combine Apache Access Logs in cPanel

This post explains how to combine Apache access logs in cPanel. As you know cPanel keeps separate access logs for each domain and that lie on the path /usr/local/apache/domlogs/DOMAIN. As these logs are different for each domain, it is difficult to troubleshoot an issue. Once you combine all domain’s access logs in to a single log file, you can simply find out where the problem might lie.

If you need a global access logs for all of your domains, here are the instructions on how to get this to work:

1. Move to the directory apache2_4 and copy the file vhost.default to vhost.local

cd /var/cpanel/templates/apache2_4
cp vhost.default vhost.local

2. Alter vhost.local in a text editor like VIM and look for this line:

[% IF logstyle == 'combined' -%]
[%- IF !enable_piped_logs || !supported.mod_log_config -%]
CustomLog [% paths.dir_domlogs %]/[% wildcard_safe(vhost.log_servername) %] combined
[%- END %]

Just after the ‘CutomLog‘ string, add this:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcommon
CustomLog /usr/local/apache/logs/vhost-access_log vcommon

So it looks like this:

[% IF logstyle == 'combined' -%]
[%- IF !enable_piped_logs || !supported.mod_log_config -%]
CustomLog [% paths.dir_domlogs %]/[% wildcard_safe(vhost.log_servername) %] combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcommon
CustomLog /usr/local/apache/logs/vhost-access_log vcommon
[%- END %]

3. Then run /scripts/rebuildhttpdconf so it’s rebuilt, and then restart Apache so the logfile will be created.

/scripts/rebuildhttpdconf
service httpd restart

Please note that all the domain’s access logs directed to the file “/usr/local/apache/logs/vhost-access_log” after this configuration. If you need to view the logs for each domain individually too as it should be before in “/usr/local/apache/domlogs/DOMAIN”, you should disable Piped Apache Logging.

WHM »Service Configuration »Apache Configuration »Piped Log Configuration

That’s it!

Also Read: Locations of Log Files on cPanel Servers

If you like this post and wish to receive more articles from us, please like our FB page: Button

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at info@grepitout.com