The Apache webserver stores its logs in the ~/logs
directory, which is located in your environment’s root directory when you log in via SSH or SFTP. For information on the different types of log files and where to locate them on your Servebolt environment, visit our log file location guide.
How to View and Examine Log Files
In this guide, you’ll find useful Linux commands with explanations of how they are used to view and examine the AccessLog
and ErrorLog
. If you want to explore commands beyond the scope of this guide, please refer to our separate guide on helpful WP-CLI commands.
All commands and examples provided in this guide demonstrate accessing the log files via SSH.
cat
cat [filename]
Prints the content of a file to the console in the directory you are in, for example: cat ~/logs/AccessLog
, or cat ~/logs/ErrorLog
For more usage information, run: cat --help
zcat
zcat [filename]
Prints the content of the gzip file to the console in the directory you are in, for example: zcat ~/logs/AccessLog-20211201.gz
, or zcat ~/logs/ErrorLog-20211201.gz
For more usage information, run: zcat --help
tail -f
tail -f [filename]
Continuously prints the end of a file to the console in the directory you are in, in real-time. For example: tail -f ~/logs/
Another example is when you want to display log entries in real-time but only for files ending with “Log”, you can add the argument /*Log
at the end: tail -f ~/logs/*Log
You can also specify AccessLog or ErrorLog to be followed in real-time, for example: tail -f ~/logs/AccessLog
, or tail -f ~/logs/ErrorLog
For more usage information, run: tail --help
grep
In the coming examples, we use a pipe: |
in combination with the commands. Doing so allows you to pass the output of one command directly as input to another.
grep ‘word’ [filename]
Prints the lines that match the given string in the specified file. For example: grep 'string' AccessLog
, or grep 'string' ErrorLog
Grep is useful when searching for strings within the specified file, as it prints the matching lines. Here’s an example where we search for status codes of 200 in the AccessLog: cat ~/logs/AccessLog | grep " 200 "
We can also use grep in real-time with the same example by combining it with the tail command: tail -f ~/logs/AccessLog | grep " 200 "
For more usage information, run: grep --help
wc -l
In the coming examples, we use a pipe: |
in combination with the commands. Doing so allows you to pass the output of one command directly as input to another.
wc -l [filename]
Counts and prints the number of lines present in the specified file. The wc
stands for “word count”, and the -l
option specifies that you want to count the lines.
Combining the wc -l and grep commands will display the number of lines that match the specified search. For example, when searching for status codes of 200 in the AccessLog and printing the number of lines that match the search: cat ~/logs/AccessLog | grep " 200 " | wc -l
For more usage information, run: wc --help
As always, should you have any additional questions, please don’t hesitate to contact us through our support chat at servebolt.com!