Cannot get php display_errors enabled
Hey i know there are a few posts regarding this topic and i have scoured them all!
I cannot not enable the display_errors setting in php no matter what i do!!!
Im using virtual box with php 5.3 installed with apache2 running. i have tried everything i can think of to get display errors working but no开发者_JS百科thing seems to work.
I have set php_flag display_errors on in my .htaccess file i have even enabled it directly in the php.ini file
display_errors = 1
and also tried
display_errors = On
I am using the defaults for apache sites-enabled is there something i need to do here to get this to work?? i have never had this problem running php on my mac using mamp.
Any suggestions would be greatly appreciated this is driving me nuts!
You can also enable it in your PHP script usually:
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
If that doesn't help, then try a quick workaround first:
set_error_handler("var_dump");
Could be used to replicate the original behaviour, if it's suppressed by some other circumstance.
Take in mind, this only works for enabling runtime errors. If you suspect parse errors, you'll definitely have to enable error display in the php.ini / .htaccess / .user.ini. -- Else make a wrapper
test.php
script with above instructions, theninclude()
the faulty script.
Actually, in php.ini
there are two places where you can encounter display_errors
line. By mistake you can enable first one, but it is overriden by the last display_errors = Off
(such misleadming thing happened with me).
There is block that goes first in the file:
;;;;;;;;;;;;;;;;;;;
; Quick Reference ;
;;;;;;;;;;;;;;;;;;;
; The following are all the settings which are different in either the production
; or development versions of the INIs with respect to PHP's default behavior.
; Please see the actual settings later in the document for more details as to why
; we recommend these changes in PHP's behavior.
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off
And the last occurance of display_errors
much lower in the file:
; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; It's recommended that errors be logged on production servers rather than
; having the errors sent to STDOUT.
; Possible Values:
; Off = Do not display any errors
; stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
; On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
; http://php.net/display-errors
display_errors = Off
Be sure to change last occurence of display_errors
. Just set it to display_errors = On
, restart Apache and you'll get what you need.
Per display_errors
:
Although
display_errors
may be set at runtime (withini_set()
), it won't have any effect if the script has fatal errors. This is because the desired runtime action does not get executed.
so if you are dealing with problem not displaying errors and you may have syntax errors in your scripts, setting displaying errors by ini_set will not help, this requires changes in php.ini
sudo sed -i 's/display_errors = Off/display_errors = On/' /etc/php5/apache2/php.ini
I usually use (in the PHP script I try to debug):
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
That usually does the job, but if you have a nasty unmatched parenthesis it could not suffice. So if it doesn't still work, it could depend on some PHP buggy code.
It could even be that you are editing the wrong php.ini: use phpinfo() and search for the parts under "Loaded Configuration File" and "Additional .ini files parsed".
P.S. : display_errors = 1
and display_errors = On
in php.ini are equivalent.
Try error_reporting = E_ALL
. Also, are you sure that you are editing the correct php.ini?
Please try:
grep "display_errors" /etc/php5/apache2/php.ini
Just to check how many time it appears.
For anyone that tried these and nothing worked, make sure you're editing the right config file /opt/lampp/etc/php.ini
and not /etc/php/php.ini
.
In my case, what I had to do is
set_error_handler(NULL);
<the code to debug on screen>
restore_error_handler();
I had defined a custom error handler, which entirely bypassed the default PHP error handler. Yet, I did not want to remove my custom error error handler permanently. So, I used set_error_handler(NULL);
to reset the error_handler to its default value. I used restore_error_handler();
to get back my original custom error_handler.
In my case, I had switched display_errors to On, but I had forgotten to restart Apache afterwards. Hopefully this helps someone!
精彩评论