Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I did something stupid about 1 million times in a PHP script so my apache error log is now 12 megs! Not exactly a good situation to be in for debugging.

  1. Under what conditions does the error.log get turned into error.log.1 and error.log.2.gz?
  2. Is there a linux command that will roll the logs over manually to get a fresh error.log

I was hoping someone knows an easy way to accomplish this. If not I'll write a BASH script.


share|improve this question

migrated from Jan 29 '12 at 13:38

This question came from our site for professional and enthusiast programmers.

There are standard ways to do this. Ask on serverfault. – Steven Parkes Jan 28 '12 at 18:29
You can simply delete the file, it will be recreated – knittl Jan 28 '12 at 19:27
@smparkes - thanks, I did find this issue on serverfault. For anyone who wants to know it is $>logrotate -f – James L. Jan 28 '12 at 19:44
  1. Your logs are rotating because of log rotate tool
  2. You can rotate logs manually with this command. if you want to rotate your apache logs.

logrotate /etc/logrotate.d/apache2 or (file_to_be_rotated)

This tool help you to administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

share|improve this answer

Removing the file and sending HUP signal to the process writing to the log file is the canonical thing to do.

For apache, it's better to reload the service.

share|improve this answer

This doesn't answer your question directly, but it might give you some more options. Apache allows you to pipe the output of your logs to processes that read from stdin. My preferred strategy for avoiding enormous logfiles is to pipe Apache's log output through a utility called cronolog that's available as an optional package on most Linux installations. It doesn't rotate out to files named error_log.1, error_log.2, etc, but instead it can do so by date and/or time.

For example:

ErrorLog  "|/usr/bin/cronolog /path/to/httpd/logs/error_log.%Y-%m-%d"

This will send error logs from February 1, 2012 to a file named error_log.2012-02-01 and as soon as the time rolls over to February 2, 2012, it will start writing to error_log.2012-02-02 and so on.

You can also set it to rotate just by month, or by weekday, or by hour, or minute, or second, whatever you need. More information at

If you're really ambitious, you could write your own Perl script or whatever to read from stdin and write to log files or perform actions (like emailing you) using whatever rules you want, and pipe Apache's logs through that instead.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.