cPanel/WHM Dom logs to remote syslog server

There is any native support in cPanel service to send apache logs of all domains or any other logs on a remote server directly. Therefore, Some custom changes needed to send logs to remote server. So, first let’s list out all the domain name from the cPanel/WHM server. listing all the hosted domain on whm server

cat /etc/userdomains | awk -F':' '{print $1}' | grep -v '*' | wc -l

cat /etc/userdomains | awk -F':' '{print $1}' | grep -v '*' > domainlist.txt

I’ve also written a simple bash script to make custom changes on apache configuration httpd.conf file. I’ve got 210 total domain and to make changes on every virtual host directive is quite time-consuming. Also, we have to append the below line for every domain.

CustomLog "| /bin/sh -c '/usr/bin/tee -a /usr/local/apache/domlogs/ | /usr/bin/logger -thttpd -plocal1.notice'" combined

Below script will first check for the line “CustomLog /usr/local/apache/domlogs/ combined” in an httpd.conf file and if found then script will append another CustomLog line below that line.


for domain in $(cat domainlist.txt)
/bin/sed "/CustomLog \/usr\/local\/apache\/domlogs\/$domain combined/ a CustomLog \"\| \/bin\/sh -c \'/usr/bin/tee -a \/usr\/local\/apache\/domlogs\/$domain \| \/usr\/bin\/logger -thttpd -plocal1\.notice\'\" combined" /etc/httpd/conf/httpd.conf -i

Now restart the apache service but first check configuration.

http -t
service httpd restart

Now add remote log server IP and port number on /etc/rsyslog.conf file. In my case, IP listening on UDP port 514.

Single @ for UDP and double @@ for TCP connection. vim /etc/rsyslog.conf

*.* @    
local1.notice @

Now restart rsyslog service.