• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Web Hosting Resource Kit

Web Hosting, Web Hosting Reviews & Virtualization

  • Contact
  • About Us
  • Privacy Policy

This post may contain affiliate links. If you use these links to buy something we may earn a commission. Thanks.

How to rotate your Apache Log Files?

July 24, 2007 By Christoph Puetz Leave a Comment

  • Tweet
  • Sumo
  • Tweet

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.

 

Related posts:

  1. Upgrade To APACHE 2.0 Web Server
  2. Apache Webserver – A quick tutorial for new Admins
  3. Apache HTTP Web server configuration Tutorial
  4. Restoring Domain Accounts and Server Config Files with WHM / cPanel
  5. How to remove or disable mod_evasive from Apache Web Server?
  6. What is Mod_Security (on cPanel server)?
  7. How to write a cron job?

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Categories

  • Business Management
  • Editors Column
  • Hosting Customers
  • Interviews & PR
  • Marketing/Advertising
  • Online Marketing/SEO
  • VMWare
  • Web Host Startup
  • Web Hosting
  • Web Hosting Reviews

Pages

  • About Us
  • Contact
  • Disclosure Policy
  • Privacy Policy
  • Sitemap
  • Terms of Service
  • Welcome to Web Hosting Resource Kit

Copyright Webhostingresourcekit.com© 2022 · Log in