How to Read Apache Log Files


how to read apache log

Apache is an excellent web server that provides robust logging features, helping you track all responses and error messages. It is important to know how to read server logs so you can easily diagnose and fix website issues. Let us take a look at how to read Apache log files.

 

How to Read Apache Log Files

Here are the steps to read Apache log files. Apache logs information in 2 log files – access.log and error.log

Access.log is used to log each and every request received by your Apache server. It also provides additional information about visitors such as their IP address, web browser, response code, requested URL, etc.

Error.log is used to log each and every error encountered while running Apache server. It contains detailed information about every error response allowing you to debug your application easily.

Depending on the type of Server installation, they are located in different places.

 

Managed Dedicated Server & VPS

If you have managed dedicated server & VPS, you will be able to access Apache logs only via CPanel. Log into CPanel, and click on Raw Access in Metrics section or Raw Access Logs in Logs section, depending on your CPanel version.

 

Unmanaged Dedicated Server & VPS

In this case, you have root access so you can easily access the raw log files by simply doing SSH into your server.

 

You will find Apache access log at:

For Ubuntu/Debian


/etc/httpd/logs/access_log

For CentOS/RHEL/Fedora:


/var/log/apache2/access.log

 

Similarly, you will find error logs at

For Ubuntu/Debian


/etc/httpd/logs/error_log

For CentOS/RHEL/Fedora


/var/log/apache2/error.log

 

How to Read Apache Logs

Apache log files are large since they have so much data. So you need to use head/tail commands to see the first/last lines in your server logs. Each log entry is appended at the end of the file. So the last few entries contain information about the most recent requests.

 

For example, if you want to read the last 10 lines of your access log, run the command

For Ubuntu/Debian


$ sudo tail -10 /etc/httpd/logs/access_log

 

For CentOS/RHEL/Fedora


$ sudo tail -10 /etc/httpd/logs/access.log

 

Similarly, if you want to read the last 10 lines of your error log,

For Ubuntu/Debian


$ sudo tail -10 /etc/httpd/logs/error_log

For CentOS/RHEL/Fedora


$ sudo tail -10 /etc/httpd/logs/error.log

 

If you want to look for a particular string in your Apache logs, use the grep command

 

For example, if you want to retrieve all HTTP GET requests, look for “GET” keyword in your log

For Ubuntu/Debian


$ sudo grep GET /etc/httpd/logs/access_log

For CentOS/RHEL/Fedora


$ sudo grep GET /etc/httpd/logs/access.log

 

Similarly, if you want to get all the “invalid” requests to your server

For Ubuntu/Debian


$ sudo grep invalid /etc/httpd/logs/error_log

For CentOS/RHEL/Fedora


$ sudo grep invalid /etc/httpd/logs/error.log

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!