error in php not logging or displaying
Solution 1
I can see a few possible solutions to your problem. These are the most common issues you'll run into:
- In your example, you use
#@$%$
to induce an error. However, PHP treats any line beginning with a hash as a comment, so this line would never be evaluated, hence it would never trigger an error condition. - There are 2 distinct
php.ini
files that you should be aware of; one for Apache and one for the PHP CLI. Make sure that the one you've edited is the one for Apache if your script is being called from a web browser. The directory that this file is found in will vary from distro to distro, but the default path is usually a slight variation of/etc/php/apache/php.ini
- You must restart Apache after making changes to the
php.ini
file, or send a SIGHUP to Apache to force a re-read of the configuration file. - The
error_reporting
andlog_errors
configuration variables can be overwritten locally within an Apache vhost file, or even in the PHP script itself. Make sure that the default server config does not overwrite these variables locally in the Apache configuration for the vhost you're using. - The permissions of your
/var/log/php.log
file need to be writeable by Apache. It's usually safe to set the owner of this file to the Apache user on your system (the Apache user is usually eitherwww-data
orapache
).
Solution 2
It seems like the display_errors or error_reporting were overridden by something else.
It happened to me by an application that changes the error_reporting later in the bootstrap which I didn't see.
A good practice is to search for error_reporting within the application and see it is modified somewhere.
Solution 3
In the past, I had no error logs in two cases:
- The user under which Apache was running had no permissions to modify
php_error_log
file. - Error 500 occurred because of bad configuration of
.htaccess
, for example wrong rewrite module settings. In this situation errors are logged to Apacheerror_log
file.
Related videos on Youtube
Grant M
Updated on September 17, 2022Comments
-
Grant M almost 2 years
I can not get any errors to display on screen on write to a log file. When check phpinfo() print out I have same value of master a local for
display_errors On display_startup_errors On error_log /var/log/php.log error_reporting E_ALL & ~E_NOTICE log_errors On log_errors_max_len
ls -l /var/log/php.log is -rw-rw-rw- 1 root root 0 Jun 21 07:47 /var/log/php.log for /var and /varlog drwxrwxrwx 23 root root 4096 Jun 2 11:13 var
when there is an error in the code the page the browsers shows nothing and browser says there is no source for the page. Any suggestions of where else to look or change to errors to appear somewhere (anywhere would be good)
edit: my error script is now
<?php ini_set('display_errors', 1); error_reporting(E_ALL); echo "print from error.php 2 "; error //print from erroerror to cuase logging to happen. ?>
this will print on display and to log
Notice: Use of undefined constant error - assumed 'error' in /var/www/piku_dev2/error.php on line 7
but if I put garbage like #@$%$ on the error line I get nor error messages anywhere.
Edit2: The problem turned out to in the httpd.conf file. I don't know what it was yet as it was fixed y someone else.
-
Lèse majesté about 14 yearsIt's possible to use
error_reporting()
to change the error reporting level during run-time. But how do you know this is caused by a PHP error? And this is an unlikely scenario, but the script could be using the error suppression operator@
and just terminating the script withdie
before any output is printed.
-
-
haxpor over 7 yearsThanks, this helps me. I have to create a target log file and set permission and owner to
www-data
. This is on ubuntu 14.04.