Beginner Fundamentals
Logging Requests and Errors
Apache records every request and any problems in log files. Logs are essential for debugging and monitoring traffic.
Default Log Locations
- Debian/Ubuntu:
/var/log/apache2/ - Red Hat/CentOS:
/var/log/httpd/
Access Log
The access log records each request. You define its format and path:
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog /var/log/apache2/access.log common
Common format codes:
%h: client IP address.%t: time of the request.%r: the request line.%>s: response status code.%b: size of the response.
Error Log
The error log captures problems and warnings:
ErrorLog /var/log/apache2/error.log
LogLevel warn
LogLevel controls how much detail is recorded, from debug to error.
Watching Logs Live
sudo tail -f /var/log/apache2/access.log
sudo tail -f /var/log/apache2/error.log
Per virtual host, you can set separate log files so each site has its own history. Always check the error log first when something does not work.