Rotate Apache log files on Ubuntu Hardy Heron server

by JC on September 16, 2008 · 0 comments

in Settings

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:

  1. Ubuntu server distro direct-upgrade
  2. How to change time-zone on a Linux server
  3. Sort Highrise email addresses by tag and check for duplicates in Excel
  4. Life-sized RX78 Gundam
  5. Slicehost: a quick, fun way to learn Linux server administration

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post: What is PPC ?

Next post: Slicehost: a quick, fun way to learn Linux server administration