The Apache webserver stores its logs in the
/logs folder which you can find in the root of your site when you log in with SFTP or SSH. For commands used in this article, SSH is the recommended choice. The
AccessLog contains all requests that are passed back from the front-end webserver (nginx), typically the traffic of your site. The
ErrorLog by default will contain the PHP errors your site produce, but also more general errors caused by your application.
CLI commands used to view and examine log files
Down below you can find some examples on how you can view and examine the
cat [filename] For manual, use:
Print contents of file to console in the directory you are in, example:
cat ~/logs/AccessLog, or
zcat [filename] For manual, use:
Print contents of gzip file to console in the directory you are in, example:
zcat ~/logs/AccessLog-20211201.gz, or
tail -f [filename] For manual, use:
The following command will display log entries as they are added in real time for all files ending in “Log”:
tail -f ~/logs/*Log
You can also specify AccessLog or ErrorLog to be followed in real time, example:
tail -f ~/logs/AccessLog, or
tail -f ~/logs/ErrorLog
grep ‘word’ [filename] For manual, use:
Grep is used to search for strings and print the lines that match it. 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 using tail:
tail -f ~/logs/AccessLog | grep " 200 "
In these examples we use pipe ( | ) in combination with grep. Pipe will use two or more commands to output from the left of it, and input it to the right.
wc -l [filename] For manual, use:
You can also use
wc -l to print the number of lines present in a file, or that match the search using
grep. Example where we search for status codes of 200 in the AccessLog and print the number of lines that match the search:
cat ~/logs/AccessLog | grep " 200 " | wc -l
Give us your feedback on this article
Want to speed up your site, easily?
Set up your site on Servebolt, free of charge for 60 days, and see for yourself how fast it can be on our extremely fast hosting.
A faster site converts better, ranks better on Google, and is better for the climate.