Apache2 Web Server Logs – How To

Valic —  July 2, 2011 — Leave a comment

Log Files:
Log files are critical to managing Apache.
Managing these logs can provide advance security warnings, provide detailed information in terms of who is visiting your site and where they are coming from and can help you troubleshoot the use of your server resources. The two main log files are listed below from a Debian Squeeze Server.
The access_log file gives you information on who is using your web server and the error_log provides information for troubleshooting.


How to View Apache2 Logs:

View apache2 logs with tail and head:

The basic tail command will show the tailend of the log.

tail /var/log/apache2/access_log

You can use the -n option to view a specific number of lines  like in this example:

tail -n100 /var/log/apache2/access_log

Head is the opposite of tail.

head /var/log/apache2/access_log


head -n200 /var/log/apache2/access_log

Viewing Logs with cat command:

cat is another method of viewing logs.  The whole log may be listed with this command:

cat /var/log/apache/access_log

Another  way to view logs would be to use less:

less /var/log/apache2/access_log

You can also use grep command to search for text strings.

grep warning  /var/log/apache2/access_log

View Logs in Real Time:
The command tail used with the -f option will provide real time activity like this:

tail -f /var/log/apache2/access.log


Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

No Comments

Be the first to start the conversation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.