This is not a comprehensive list of log files on any given CentOS Linux hosting box. This is a quick guide to what you may need to know as a LAMP developer.
A Little background information on logging
The Linux operating system can seem mysterious until you learn your way around. As a LAMP developer you do not need to know as much as a full blown Linux system administrator. However armed with some basic information about how Linux works will make your life much simpler. This information will also make you more productive and independent.
CentOS is configured to write to these log files information about the system and different processes that are running. You can use these logs to troubleshoot any problem you are having from HTML and PHP errors to shell access difficulties.
Lots of daemons create their own files. These files are “rotated” in an effort to keep them manageable and so they do not grow too large.
A program named logrotate is responsible for managing these files or “rotating” them. Logrotate is run daily via a crontab, which is located at /etc/cron.daily/logrotate. The configuration file is located at /etc/logrotate.conf. logrotate.conf is where you can configure how often the logs are rotated and how long they will be kept. On my development box the logs are set to rotate weekly and are kept for 4 weeks. This is the default.
Individual daemon log configuration files are located in the /etc/logrotate.d/ directory.
Log Files You Will Want To Review On a Regular Basis
As a LAMP developer you will be interested in a subset of all the logs that are available.
- messages – Contains information on the boot process.
- secure – Check this log if you are trying to find out why someone is unable to login via SSH.
- dmesg – Is probably not a log you will be interested in unless you are trying to troubleshoot your hardware.
- The httpd folder contains several logs you will be interested in. The access_log and error_log. This directory will also contain some SSL log files if you have configured an SSL certificate.
- mysqld.log – Contains messages specific to the MySql data server operation.
- php_error_log – If your system has been configured to log PHP errors you may find a file named php_error_log in the /var/log directory. I mention this log because it is not configured by default. However you may want to add this log file to gather more information about any PHP errors that might be occurring [add link to article]
- cron – This log will come in handy if you want to know what is occurring with the cron jobs you are working with.
Commands to use to review your log files
- cat – Will list the contents of a test file.
- tac – The opposite of cat. List the contents of a text file from newest entry to oldest entry.
- tail – lists the last few lines of the text file. See the man page for more information.
- tail – f will display the errors as they are added.
You may want to pipe the output through less or more.
When you list the log files contained in /etc/log you will notice there is a lot of logs. Those other log files are outside the scope of this article. I limited this article to just the handful of logs you may be interested in as a LAMP developer.
We covered a little information on how logging works on CentOS, which logs are most important to a LAMP developer, and how to list out the logs. Once you know where to look things become less mysterious and easier to deal with. This article is targeted towards the PHP Programmer that is working on a LAMP server running CentOS.