Cannot get php display_errors enabled

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.


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, then include() the faulty script.


Per display_errors:

Although display_errors may be set at runtime (with ini_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

Tags:

Php

Apache