Apache log files like error.log and access.log can cause Apache to stop working once they exceed a certain size. However, I haven’t encountered this issue on Linux servers (I recommend using Linux for servers whenever possible — it’s incredibly stable, though configuring it can be a real pain, heh……).
How to clear error.log, access.log and limit Apache log file size:
Of course, the simplest method is manual cleanup, but that’s not only time-consuming but also requires stopping the server before cleanup, which is clearly impractical.
Below, we’ll use Apache’s built-in tools to set log file size limits and automatic generation.
Step 1: Stop all Apache service processes and delete the error.log and access.log files in the Apache2/logs/ directory
Step 2: Open Apache’s httpd.conf configuration file and locate the following two lines
ErrorLog logs/error.log
CustomLog logs/access.log common (This line is usually not present by default)
ErrorLog logs/error.log
CustomLog logs/access.log common (This line is usually not present by default)
Comment them out directly and replace with the following configuration.
# Limit error log file to 1M
ErrorLog "|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log 1M” (It’s best to use absolute paths, which I’ll omit here)
# Generate a new error log file daily
#ErrorLog "|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log 86400"
#ErrorLog "|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log 86400"
# Limit access log file to 1M
CustomLog "|bin/rotatelogs.exe -l logs/access-%Y-%m-%d.log 1M” common
CustomLog "|bin/rotatelogs.exe -l logs/access-%Y-%m-%d.log 1M” common
# Generate a new access log file daily
CustomLog "|bin/rotatelogs.exe -l logs/access-%Y-%m-%d.log 86400" common
CustomLog "|bin/rotatelogs.exe -l logs/access-%Y-%m-%d.log 86400" common
After completing the configuration above, restart your Apache service. Log files will then be generated with date-based filenames, and a new log file will be automatically created each day.