Apache · Configuration and operations
How do Apache logs work and how do you manage them?
Short answer
Apache writes access logs per request and error logs for diagnostics. Configure them per virtual host where useful, set an appropriate LogLevel, and rotate files with logrotate or a piped logger to avoid filling the disk.
Access logs record requests and responses; error logs record startup messages, warnings and request failures. Both can go to files, syslog or a pipe. In containers, writing to stdout and stderr is usually preferable so the platform collects and rotates logs.
ErrorLog /var/log/apache2/error.log
LogLevel warn
LogFormat "%v %h %l %u %t %r %>s %b %D %{Referer}i %{User-Agent}i" vhost_combined
CustomLog /var/log/apache2/access.log vhost_combined
<VirtualHost *:443>
ServerName example.com
ErrorLog /var/log/apache2/example-error.log
CustomLog /var/log/apache2/example-access.log vhost_combined
</VirtualHost>Operations
- LogLevel warn is a reasonable production default; trace levels are for short investigations
- Separate virtual host logs when you need per-tenant retention or access control
- Rotate with logrotate and signal Apache to reopen files after rotation
- Piped loggers such as rotatelogs can rotate without a reload
- Ship logs off the host so a disk failure does not lose the only copy
- Avoid logging secrets, tokens and full request bodies
If Apache cannot write to a log file, it may fail to start or stop logging. Check permissions on the log directory and whether the service account can create files there. A full disk caused by unrotated logs is a classic outage.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between the access log and the error log?
- 2How do you rotate Apache logs without losing entries?
- 3Why would you use a piped logger?
- 4What should you avoid logging?
Say it in the interview
Access logs record requests and error logs record diagnostics. I configure LogLevel carefully, keep per-vhost logs where retention matters, and always rotate or pipe logs so they cannot fill the disk. In containers I prefer stdout and stderr. I also treat logs as sensitive data and avoid writing tokens or bodies.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Apache mock interview and get scored feedback on depth, clarity and confidence.