grayloon

Well-Known Member
Oct 31, 2007
118
4
68
Evansville, IN
cPanel Access Level
Root Administrator
Twitter
I just switched from EA3/Apache 2.2 to EA4/Apache 2.4. Previously, I had a the following in my
/usr/local/apache/conf/includes/pre_main_global.conf file:
Code:
<IfModule mod_log_config.c>
    LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" mycustom
</IfModule>
Then, I had the following in /usr/local/apache/conf/userdata/global-access_log.conf:
Code:
CustomLog /var/log/httpd/global-apache-access_log mycustom
That was working great for several years. Now, I'm trying to set up the same thing with EA4, and I can't get it to log to the global log file. I added both of those directives to /etc/apache2/conf.d/includes/pre_main_2.conf, I added them to the bottom of my httpd.conf file, but nothing is working. I searched the forums and found all types of answers spanning several years. Is there currently a definitive way to do this?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,226
463
Hello @grayloon,

You should be able to complete the following steps to customize the LogFormat entry:

1. Copy the Apache 2.4 template for EasyApache 4 to allow for customization:

Code:
cp -a /var/cpanel/templates/apache2_4/ea4_main.default /var/cpanel/templates/apache2_4/ea4_main.local
2. Edit /var/cpanel/templates/apache2_4/ea4_main.local to change the entries to match your preferences:

Code:
vi /var/cpanel/templates/apache2_4/ea4_main.local
Note: You can make custom changes/additions for "CustomLog" in this same file instead of creating an additional configuration file.

3. Save the changes, and then run:

Code:
/scripts/rebuildhttpdconf
Let us know if this helps.

Thank you.
 

grayloon

Well-Known Member
Oct 31, 2007
118
4
68
Evansville, IN
cPanel Access Level
Root Administrator
Twitter
I added my custom directives to the ea4_main.local file and rebuilt httpd.conf. My custom directives are in the httpd.conf file, but I'm still not seeing any output in my global log file. Here's the relevant section of httpd.conf:
Code:
<IfModule log_config_module>
    LogFormat "%{Referer}i -> %U" referer
    LogFormat "%{User-agent}i" agent
    # NOTE: "combined" and "common" are required by WHM
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" mycustom
    CustomLog /var/log/httpd/global-apache-access_log mycustom

    # access_log format can be set in WHM under 'Basic cPanel & WHM Setup'
    CustomLog logs/access_log combined
</IfModule>
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,226
463
I figured it out. I had to copy and edit the vhost.default template as well.
I'm happy to see you were able to address the issue. Thank you for updating us with the outcome.

Thank you.
 

morrow95

Well-Known Member
Oct 8, 2006
164
8
168
If using this method will the changes 'stay'? The first thing that shows in this file is :

----
# Direct modifications to the Apache configuration file WILL be lost upon subsequent
# regeneration of this configuration file, or an Apache update.
#
# To have your modifications retained, you should create/edit administrator-specific
# include files:
#
# [% paths.dir_conf_includes %]/pre_main_global.conf
# [% paths.dir_conf_includes %]/pre_virtualhost_global.conf
# [% paths.dir_conf_includes %]/post_virtualhost_global.conf

----

I'm just trying to understand how this .local copy with a few changes to the file here and there fits into everything. It reads the default first then the local and overwrites anything that is different? What happens when a change is made to the default and our local 'copy' doesn't have those new changes... in that situation you'd be overwriting any new changes right because your copy is 'old' just with your custom modifications.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,226
463
What happens when a change is made to the default and our local 'copy' doesn't have those new changes... in that situation you'd be overwriting any new changes right because your copy is 'old' just with your custom modifications.
The ".local" template takes precedence over the ".default" template. You'd have to manually update the ".local" template every time a new default template is issued. As of cPanel 64.0.19, notifications are sent when the EA4 default templates are updated and a local template file exists:

Fixed case CPANEL-12933: Notify admins of EA4 template changes if .local versions exist.

Thank you.
 

grayloon

Well-Known Member
Oct 31, 2007
118
4
68
Evansville, IN
cPanel Access Level
Root Administrator
Twitter
I'm diving back into this, because a cPanel support tech slapped my hand for having a really outdated .local file in place. I removed the file to get my server working properly, but I'd still like to use some type of global Apache logging. I turned on the piped logging feature, but I didn't see where it was creating any type of combined log for all virtual hosts. Any further suggestions?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,226
463
Hello @grayloon,

The easier approach would be to use a bash command that shows you the output of multiple or all domain access logs as opposed to changing the way Apache logs the data. You'd use less system resources this way. Is the purpose of this customization to allow you to view all of the Apache domain access logs in a single location, or is it due to some other need?

Thank you.