Today I am going to write about log which will help you to understand the concept of log in PHP, MySQL, and APACHE.The error log is a text file saved on your server.Entry will be added in this file when any error occurs. This file mainly for tracking an errors or warnings generated in the system.
Generally Error log contains information about the errors and Information are like date/time, user IP address Error message and object the user was requesting.The error message is also contained in Apache Log and it is important to pull error log data out of access log.
The main purpose of the error log is to keep track of all of the errors that occurred when your PHP pages were being accessed.
Let’s see error logs of main three PHP, MySQL and APACHE
Error logs of PHP
PHP is logging error for us but default setting of php.ini file for logging error is OFF so you have to turn on it to enable error log feature and which we highly commended. Also, you need to specify the path of the file where you want to save your error log in your php.ini file.
The typical error log entry looks like this:
1 2 3 4 | PHP Parse error: parse error, unexpected '}' in C:Program FilesApache2testtest.php on line 14 |
In the above example, you can see that there was a parse error in the file test.php on line 14, which stops the execution of the particular page. Any user trying to see the contents of this file will see only the parse error until we get it fixed. So with the regular check of PHP error log, you will make sure there aren’t any errors in your code.
Error logs of MySQL
Like PHP, MySQL is also logging error and queries that happened with database transactions.By default, the error log is stored as hostname.err in the data directory of MySQL.Although You can specify other location where the error log is saved.
If you wanted to specify a different location for the error log, You can specify the [mysqld] section in my.ini file by using following the line of code.
1 2 3 | log-error=/var/lib/mysql/error.log |
MySQL also allows us to view every query sent to the server. To specify the location log for query, you need to type the following line of code:
1 2 3 | log=/var/lib/mysql/query.log |
NOTE: By default, Log file will be stored in the “data” directory with the name hostname.log file, unless you specify.Also Read about Types of Error Levels in PHP.
Error logs of Apache
Apache keeps both access logs and error logs.When Apache has been installed on your server, the default location for your log file is
Apachelogs.
Log Format of access log is
1 2 3 4 | LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"" combined |
Let’s see access log entry and its looks like this:
1 2 3 4 | 127.0.0.1 - - [14/Nov/2011:23:32:47 +0530] "GET /logo.gif?641e5f=19684125 HTTP/1.1" 404 206. |
By Default, Access log stored in the file access.log in Apache/logs.All of this information is on one line of the log and which is built by Apache.
However, an error log is stored in error.log file which contain any errors or warnings.
Let’s see error log entry and its looks like this:
1 2 3 4 5 6 | PHP Warning: PHP Startup: Unable to load dynamic library 'C:\PHP\ext\php_apc.dll' - rn in Unknown on line 0 |
Above Warning specifies that php_apc.dll file enables in PHP.ini file but it does not exist in PHP extension directory.