Join Amazon Student FREE Two-Day Shipping for College Students!

Rotate Apache logs on a daily basis using rotatelogs in CentOS Apache 2.x

Rotate Apache logs on a daily basis using rotatelogs in CentOS Apache 2.x

If you Apache to start a new log file every day automatically, rotatelogs is the simple way to do it. Rotatelogs is a simple program for use in conjunction with Apache's piped logfile feature. It supports rotation based on a time interval or maximum size of the log.

The use of rotatelogs is actually quite simple. Search your httpd.conf and replace the following line

CustomLog logs/access_log combined


CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/access_log.%Y-%m-%d 86400" combined

86400 (= 60 * 60 * 24) which causes a new log file each day at midnight

The rotatelogs in default record log using GMT time. If your system is using local time rather than GMT, you need to add -l option.

CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/access_log.%Y-%m-%d 86400" combined

Now check if the syntax is OK and give Apache a graceful.

Run the command below to check the configuration syntax.

/usr/sbin/apachectl configtest

Syntax OK

Graceful restart. The apachectl graceful command tells Apache that you want to restart the server gracefully without aborting any open connections. It automatically checks the configuration files before initiating the restart to make sure Apache doesn't die.

/usr/sbin/apachectl graceful

If apachectl graceful doesn't restart your server, there are a few other things you can try.

  • apachectl restart to restart the server. If the server is not running it is started. This command also runs a configuration test to make sure Apache won't die when it restarts.
  • apachectl stop to stop the Apache server
  • apachectl start to start the Apache server (will throw an error message if Apache is running)
  • apachectl configtest to test the configuration file syntax.

Leave a Reply

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


Your browser is out-of-date. Upgrade your browser today! Internet Explorer | FireFox | Chrome