CHAPTER 8 How to Fix The Web: Obscure Back-End Techniques and Terminal Secrets
web SeRveR eRRoR logS
If it failed to start and didn’t give a friendly error message, the next place
to look is the error logs. These are usually in the /var/log directory named
after the software. Run ls /var/log to double check. For example, Apache’s
logs are in /var/log/apache2.
$ ls -l /var/log/apache2/*log*
-rw-r----- 1 root adm 1944899 May 5 09:59 /var/log/nginx/access.log
-rw-r----- 1 root adm 538152 May 4 02:40 /var/log/nginx/access.
log.2.gz
-rw-r----- 1 root adm 28647 May 5 08:18 /var/log/nginx/error.log
-rw-r----- 1 root adm 5701 May 4 02:35 /var/log/nginx/error.log.2.gz
This shows that Apache has an access log and an error log. Both logs are
zipped up around 02:30 each morning. The next command first changes
into the /var/log/apache2 directory with the cd command, and then uses
tail to view the last few entries in a log file.
$ cd /var/log/apache2; tail error.log
To look at a gzipped log file, use the zcat command to output it and
pipe through tail. The -20 shows the last 20 lines.
$ zcat error.log.2.gz | tail -20
Or better yet, just look for errors using grep. Use zcat with the -f
option to display both normal and zipped log files. Then pipe the output
through grep to search for the word “error” case insensitively:
$ zcat -f error.log* | grep -i error
This command may produce a lot of output. If a Matrix fan happens to
walk past your computer right now, they’ll be impressed to see all that raw
data whizzing by. It won’t help you much, though, so pipe it through less:
$ zcat -f error.log* | grep -i error | less