logrotate

Quick logrotate example for Apache logs and some gotchas

On one server, where I have a custom directory where all the Apache (httpd) error and access logs are written, one set per virtualhost, I noticed the folder had grown to multiple gigabytes in size (found using du -h --max-depth=1)—in this situation, there's a handy utility on pretty much every Linux/UNIX system called logrotate that is made to help ensure log files don't grow too large. It periodically copies and optionally compresses the log files and deletes old logs, daily, monthly, or on other schedules.

For this server, to quickly fix the problem of growing-too-large log files, I added a file 'httpd-custom' at /etc/logrotate.d/httpd-custom, with the following contents:

/home/user/log/httpd/*log<br />
/home/user/log/httpd/*err<br />
{<br />
rotate 5<br />
size 25M<br />
missingok<br />
notifempty<br />
sharedscripts<br />
compress<br />
postrotate<br />
/sbin/service httpd reload &gt; /dev/null 2&gt;/dev/null || true<br />
endscript<br />
}<br />