The PHP error_log method does not write errors to the custom error log file. It will only write to /var/log/apache2/php_error.log
Here are the logging settings in my php.ini
:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE
display_errors = Off
log_errors = On
log_errors_max_len = 0 ; also tried with 9999999
error_log = /var/log/apache2/php_errors.log
PHP writes its errors to the regular Apache error log (/var/log/apache2/error.log
) rather than the one I specified above.
Things I already tried:
/var/log/apache2/php_errors.log
is 777 permissions and the file exists.(FYI: I'm using Apache/2.2.17 and PHP/5.3.5-1ubuntu7.2 on Ubuntu 11.04)
What am I doing wrong?
Enable Error Logging in php. If you want to enable PHP error logging in individual files, add this code at the top of the PHP file. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); Now, you must enable only one statement to parse the log errors in the php.
If the syslog is used, then all PHP errors will be sent directly to the default system log file—in Linux, this is typically /var/log/syslog. The more manageable method is to use a custom log file.
Log messages can be generated manually by calling error_log() or automatically when notices, warnings, or errors come up during execution. By default, the error log in PHP is disabled. You can enable the error log in one of two ways: by editing php. ini or by using ini_set.
I'd like to answer this as it's a high result on Google even though it's an old question.
I solved this by adding write permissions for all users on the log directory.
In my case, the user 'http' needed to be able to write to /var/log/httpd/ so I ran
# chmod a+w /var/log/httpd
If the file already exists, it may help to delete it first and allow Apache to create it.
My php.ini file included the entire path, also.
error_log = /var/log/httpd/php_errors.log
You could try specifying the filename like this:
I'm using Apache 2.2.22 on Ubuntu.
Use this PHP command:
error_log("eric", 3, "/home/el/error.log");
The first parameter is the message to be sent to the error log. The 2nd parameter 3
means "expect a filename destination. The third parameter is the destination.
Create the file /home/el/error.log and set its ownership to this:
el@apollo:~$ ll error.log
-rwxrwxr-x 1 www-data www-data 7 Dec 13 14:30 error.log
When the PHP interprets the error_log method, it appends the message to your file.
Source: http://www.php.net/manual/en/function.error-log.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With