How to rotate your Apache Log Files?

Article By : admin | User Rating : Average Rating : 8.00 From 2 Voter(s)

How to rotate your Apache Log Files?

 

 

Cpanel does a good job with rotating Apache log files for the different domains on a cpanel/WHM server, but they are still not doing anything good to rotate the main Apache log files. To prevent problems on your server you need to setup log file rotation yourself. This should be done on every Apache web server and not just on a Cpanel server. Here is an easy way to do it.

 

 

 

Log into your server via SSH and switch to the root user. Now create a file for Apache log file rotation:

 

 

 

# vi /etc/logrotate.d/httpd

 

 

 

VI comes up with the new file open. Now add the following content to the new file:

 

 

 

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

 

 

 

Save the file and you are all done. But hold on. What if you wanted to go a little more sophisticated? Consider the following to extend your logging and to keep log files around for a while.

 

 

 

/var/log/httpd/*log {

 

    weekly

 

    rotate 52

 

    compress
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

 

 

 

Save it and you are done. What does this actually do? Here are all options explained for you:

 

 

 

The log files are now rotated on a weekly base. The "52" is equal to 52 weeks before log files are overwritten. To save on disk space the log files are compressed accordingly. "missingok" tells the rotation job to continue to the next file if a log file is missing and not to trigger an error. If a log file is empty it will not be rotated (notifempty). The last two options are not really critical to know for now. All we really care about are the options specified.

 



Webhostingresourcekit.com - The home of free server tutorials, web hosting tutorials, cpanel tutorials, and hosting articles. 300+ articles and tutorials of web hosting help speak a clear language.






Related Articles

- How to move a large forum from Server A to Server B?
- Linux Tutorial: How to change the IP ADDRESS on a Linux machine
- Comparing RAID 1 and RAID 5


Send to a friend Send to a friend
Rate this Article :

1

2

3

4

5

6

7

8

9

10
Poor Excellent

SEARCH:
Advanced Search
CATEGORIES:
EXTERNAL RESOURCES:
FREE RESOURCES:
VISITOR GUIDES:
 
Copyright 2004 - 2008 | Webhostingresourcekit.com |