16

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 nothing 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!

Lightness Races in Orbit
  • 358,771
  • 68
  • 593
  • 989
Mike Waites
  • 1,482
  • 3
  • 18
  • 26

9 Answers9

68

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.

Community
  • 1
  • 1
mario
  • 138,064
  • 18
  • 223
  • 277
  • 6
    Ooh, setting `var_dump` as the error handler is a _great_ idea. Thanks! – Lightness Races in Orbit May 06 '11 at 13:19
  • ini_set("display_errors", 1); setting this in my index.php has got the turned on, which is weird because that was the first thing i tried which previously didnt work. Its strange that nothing else managed to get it working, thanks for the answer though it seems to have solved the problem! – Mike Waites May 06 '11 at 13:21
  • For those reading in the future, that are like me and can't safely change display errors on the ini level, the wrapper idea for parse errors did the trick! – trex005 Dec 04 '15 at 08:18
  • Saved my life, thanks man! I can't remember how many times I just couldn't get the errors to be output, but this one does the trick! – Maciej Krawczyk May 28 '18 at 23:16
11

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.

kovpack
  • 4,597
  • 7
  • 35
  • 54
  • Thanks. I was trying to get `display_errors` on for the last hour, to no avail... The quick reference at the begining of the file is a bummer that prompts you to set it at the wrong place... – Metalcoder Sep 30 '19 at 13:29
8

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
test30
  • 2,920
  • 28
  • 24
2

Please try:

grep "display_errors" /etc/php5/apache2/php.ini

Just to check how many time it appears.

A.L
  • 9,074
  • 9
  • 55
  • 87
  • Thank you @Roman Petit. This is always a good idea. The second setting overwrites the first, if there are multiple entries. – carbontax Jan 05 '17 at 21:21
2

Try error_reporting = E_ALL. Also, are you sure that you are editing the correct php.ini?

tamasd
  • 5,396
  • 2
  • 25
  • 31
2

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.

Paolo Stefan
  • 9,358
  • 4
  • 43
  • 63
1

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.

0

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.

0

In my case, I had switched display_errors to On, but I had forgotten to restart Apache afterwards. Hopefully this helps someone!

famouspotatoes
  • 899
  • 10
  • 21