Ubuntu Hardy Heron Server comes pre-installed with a program called logrotate.d. Once you understand how this works log rotation for your Virtual Hosts is easy.
First, edit the log rotation parameters:
sudo nano /etc/logrotate.d/apache2
The standard contents of this file is:
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
if [ -f /var/run/apache2.pid ]; then
/etc/init.d/apache2 restart > /dev/null
fi
endscript
}
I simply copy and paste this function and change the initial path in the first line and link it to my Apache log files in whatever Virtual Host I want to work with. You can also modify the other parameters for more or less frequent rotation. Full instructions can be found in the logrotate manual:
man logrotate
The logorotate file is run daily by the crontab at 6.25 AM, if you need to change this type you need to edit the crontab file:
sudo nano /etc/crontab
Easy!
Related posts: