How to Check Apache Error Log and Access Log file

The Apache web server keeps two important log files: the error log and the access log. The error log contains diagnostic information, errors, and warnings, whereas the access log records all requests processed by the server. Analyzing these log files is crucial for troubleshooting issues and understanding the traffic patterns of your website.

In this guide, we will show you how to check the Apache error log and access log files on a Linux system.

Step 1: Locate the log files

The location of the log files depends on your Apache configuration and the Linux distribution. However, some common locations are:

/var/log/apache2/ (Debian/Ubuntu)
/var/log/httpd/ (CentOS/RHEL)

To find the exact location of your log files, check the Apache configuration file (usually httpd.conf or apache2.conf) for the ErrorLog and CustomLog directives. These directives define the paths for the error log and access log files, respectively.

For example, on Debian/Ubuntu, the main configuration file is /etc/apache2/apache2.conf. To find the log file locations, use the grep command:

grep -i 'ErrorLog\|CustomLog' /etc/apache2/apache2.conf

On CentOS/RHEL, the main configuration file is /etc/httpd/conf/httpd.conf. Run the following command to find the log file locations:

grep -i 'ErrorLog\|CustomLog' /etc/httpd/conf/httpd.conf

Step 2: View the log files

Once you know the location of your log files, you can use various command-line tools to view and analyze the content.

See also  How to Install and Configure yum-priorities on CentOS 5/RHEL 5 Linux Server

To view the error log file, use the tail command:

sudo tail -f /var/log/apache2/error.log

Replace /var/log/apache2/error.log with the path to your error log file. The -f option allows you to follow the log in real-time, displaying new entries as they are added.

[root@centos62 ~]# tail -f /var/log/apache2/error.log
[Thu Feb 16 18:23:08 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Feb 16 18:23:08 2012] [notice] Digest: generating secret for digest authentication ...
[Thu Feb 16 18:23:08 2012] [notice] Digest: done
[Thu Feb 16 18:23:09 2012] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 configured -- resuming normal operations
[Thu Feb 16 19:56:33 2012] [error] [client 192.168.1.52] File does not exist: /var/www/html/favicon.ico
[Thu Feb 16 23:47:07 2012] [notice] caught SIGTERM, shutting down
[Sat Feb 18 20:39:26 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Sat Feb 18 20:39:26 2012] [notice] Digest: generating secret for digest authentication ...
[Sat Feb 18 20:39:26 2012] [notice] Digest: done
[Sat Feb 18 20:39:27 2012] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 configured -- resuming normal operations

To view the access log file, use the same tail command:

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

Replace /var/log/apache2/access.log with the path to your access log file.

[root@centos62 ~]# tail -f /var/log/apache2/access.log
192.168.1.52 - - [16/Feb/2012:23:03:50 +0800] "GET /adminer/externals/jush/jush.css HTTP/1.1" 304 - "http://192.168.1.44/adminer/adminer/?server=localhost&username=root" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [16/Feb/2012:23:03:52 +0800] "GET /adminer/adminer/static/loader.gif HTTP/1.1" 200 673 "http://192.168.1.44/adminer/adminer/?server=localhost&username=root" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [16/Feb/2012:23:03:52 +0800] "GET /adminer/adminer/?server=localhost&username=root&database= HTTP/1.1" 200 4739 "http://192.168.1.44/adminer/adminer/?server=localhost&username=root" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [16/Feb/2012:23:03:52 +0800] "GET /adminer/adminer/static/plus.gif HTTP/1.1" 200 72 "http://192.168.1.44/adminer/adminer/?server=localhost&username=root&database=" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [16/Feb/2012:23:03:56 +0800] "GET /adminer/adminer/?server=localhost&username=root HTTP/1.1" 200 2977 "http://192.168.1.44/adminer/adminer/?server=localhost&username=root" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [16/Feb/2012:23:03:56 +0800] "GET /adminer/adminer/?server=localhost&username=root&script=connect HTTP/1.1" 200 109 "http://192.168.1.44/adminer/adminer/?server=localhost&username=root" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [16/Feb/2012:23:04:16 +0800] "GET /adminer/adminer/?server=localhost&username=root&status= HTTP/1.1" 200 19629 "http://192.168.1.44/adminer/adminer/?server=localhost&username=root" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [18/Feb/2012:20:39:32 +0800] "GET / HTTP/1.1" 200 1394 "-" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [18/Feb/2012:20:39:32 +0800] "GET /icons/compressed.gif HTTP/1.1" 200 1038 "http://192.168.1.44/" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
192.168.1.52 - - [18/Feb/2012:20:44:17 +0800] "GET / HTTP/1.1" 200 1394 "-" "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"

You can also use tools like grep, awk, and sed to search and filter specific entries in the log files.

See also  How to List Available Apache httpd Web Server Package and Info on CentOS 6.2

Programs Mentioned:

  • Apache HTTP Server – A widely-used, open-source web server software that powers many websites on the internet.
  • tail – A command-line utility for outputting the last part of files, commonly used to view log files in real-time.

Conclusion

In this guide, you have learned how to locate and view the Apache error log and access log files on a Linux system. Regularly checking these log files will help you troubleshoot issues, monitor server performance, and understand your website’s traffic patterns.

If you have any questions, comments, or suggestions for improvements, please feel free to share your thoughts. Your feedback helps us provide the most accurate and useful information possible.

Comments

1 Comment

  • Avatar Z says:

    This is great for a standard configuration. You’ll also want to check your Apache vhost configuration for log file locations if you need to check log files for a specific site if you’re hosting mutiple sites on your server.

Leave a Reply

Your email address will not be published. Required fields are marked *