In my forum one of user has recently posted their query regarding Apache log files and their location. First of all let’s understand what is log file and why it is important.
What’s the use of log files
Log files are used to record URL request, user activity, ip address, errors and HTTP status code for each request.
For example-
Let’s say some user is browsing https://webrewrite.com/category/php/ this page. Every time user access this page, Apache writes a log entry in access log of following things. Url requested, time of request, HTTP status code, ip address of user etc.
If you are using log in your application, then definitely it’s a best practice to log exceptions and error, which occur while running an application. These logs are helpful for debugging and improving your application.
How to Install Apache,PHP,MySql on Ubuntu
There are two types of log files used by apache.
1. Access log – All incoming requests with their HTTP status codes are log into this file.
2. Error log – All errors occured during serving requests are logged into this file. Error might be memory exhaust, file not found (404) etc.
Where Apache Logs File is Stored in Ubuntu
In Ubuntu by default Apache log file is stored in
1 2 3 |
// Path where apache log file is stored /var/log/apache2 |
To check last 5 access and error log.
tail command is used to output the last part of files. tail -5 is used to output last five lines.
1 2 3 |
// for last five error log tail -5 /var/log/apache2/error.log |
1 2 3 |
// for last five access log tail -5 /var/log/apache2/access.log |
Top Ten Most Used Linux Terminal Commands
To check first five access and error log
head command is used to output the first part of files. Similarly head -5 is used to output first five lines.
1 2 3 |
// for first five error log head -5 /var/log/apache2/error.log |
1 2 3 |
// for first five access log head -5 /var/log/apache2/access.log |