According to how you tagged the question, you are using a Redhat-style environment. Assuming you are using the stock Apache httpd installation, you are probably, behind-the-scenes, dealing with logrotate. Out of the box, logrotate executes daily out of /etc/cron.daily
. It will move your current log files out of the way, create new ones and restart httpd
such that it will begin to use the newly created, empty log files.
Check /etc/logrotate.d/httpd
. For example, the stock version shows:
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
delaycompress
postrotate
/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
endscript
}
If you add a line like this within the curly brackets, logrotate will properly rotate and re-create your log files with the correct owner and group memberships:
create 0640 root devs
This instructs logrotate to create the new log files with root
as the owner, devs
as the group, with permissions being owner read/write and group read.
You can then set your httpd log directory with permissions and ownerships like so:
chown root:devs /var/log/httpd
chmod 0750 /var/log/httpd
For the first day, you may also want to manually set the permissions on the log files and logrotate will pick up on the following days:
chown root:devs /var/log/httpd/*log
chmod 0640 /var/log/httpd/*log
You can get fancy with ACLs as demonstrated by @KuchnMar above, but this solution keeps things simple and compatible across various *nix and filesystem types.
This may be similar on a Debian-style host, but your logrotate configuration file may be called apache2
instead.
More information can be found here: