PHP not displaying errors even though display_errors = On
Asked Answered
H

18

63

I have a Ubuntu server running Apache2 with PHP 5. In the php.ini I set display_errors = On and error_reporting = E_ALL | E_STRICT, but PHP is still not displaying error messages. I'm also using Apache virtual hosts.

Also, what is the most strict error reporting PHP5.3 has to offer? I want my code to as up-to-date and future-proof as possible.

Hephzipah answered 25/6, 2011 at 20:46 Comment(1)
Make sure you check the error_log file, most of the errors are recorded there.Book
F
99

You also need to make sure you have your php.ini file include the following set or errors will go only to the log that is set by default or specified in the virtual host's configuration.

display_errors = On

The php.ini file is where base settings for all PHP on your server, however these can easily be overridden and altered any place in the PHP code and effect everything following that change. A good check is to add the display_errors directive to your php.ini file. If you don't see an error, but one is being logged, insert this at the top of the file causing the error:

ini_set('display_errors', 1);
error_reporting(E_ALL);

If this works then something earlier in your code is disabling error display.

Freestanding answered 26/6, 2011 at 16:16 Comment(1)
I missed too at first but the question title says that display_errors is On.Rudich
O
20

I had the same issue and finally solved it. My mistake was that I tried to change /etc/php5/cli/php.ini, but then I found another php.ini here: /etc/php5/apache2/php.ini, changed display_errors = On, restarted the web-server and it worked!

May be it would be helpful for someone absent-minded like me.

Orpheus answered 22/2, 2013 at 16:9 Comment(2)
wow, didn't realize I was wasting my day, I used > php -i | grep "php.ini" showed me wrong directory!Clobber
@tinybyte Because this will show you the ini of the PHP on CLI, not for CGI.Fanfare
M
7

I had the same problem on my virtual server with Parallels Plesk Panel 10.4.4. The solution was (thanks to Zappa for the idea) setting error_reporting value to 32767 instead of E_ALL. In Plesk: Home > Subscriptions > (Select domain) > Customize > PHP Settings > error_reporting - Enter custom value - 32767

Mantegna answered 24/5, 2012 at 17:30 Comment(0)
C
4

When you update the configuration in the php.ini file, you might have to restart apache. Try running apachectl restart or apache2ctl restart, or something like that.

Also, in you ini file, make sure you have display_errors = on, but only in a development environment, never in a production machine.

Also, the strictest error reporting is exactly what you have cited, E_ALL | E_STRICT. You can find more information on error levels at the php docs.

Coppola answered 25/6, 2011 at 20:47 Comment(1)
@wow are you at least able to see error messages in your error logs?Coppola
E
4

Check the error_reporting flag, must be E_ALL, but in some release of Plesk there are quotes ("E_ALL") instead of (E_ALL)

I solved this issue deleting the quotes (") in php.ini

from this:

error_reporting = "E_ALL"

to this:

error_reporting = E_ALL
Ensor answered 4/7, 2015 at 18:10 Comment(1)
Just to be clear, the reason this worked for you is because E_ALL is a global constant, not a string. #goodtoknowLaban
C
3

Although this is old post... i had similar situation that gave me headache. Finally, i figured that i was including sub pages in index.php with "@include ..." "@" hides all errors even if display_errors is ON

Cucurbit answered 4/5, 2014 at 7:7 Comment(0)
S
1

Make sure the php.ini that you're modifying is on the /etc/php5/apache2 folder, or else it won't have any efect...

Scutt answered 28/4, 2013 at 20:30 Comment(0)
F
1

Just want to add another pitfall here in case someone finds this question with a problem similar to mine.

When you are using Chrome (Or Chromium) and PHP triggers an error in PHP code which is located inside of a HTML attribute then Chrome removes the whole HTML element so you can't see the PHP error in your browser.

Here is an example:

<p>
  <a href="<?=missingFunc()?>">test</a>
</p>

When calling this code in Chrome you only get a HTML document with the starting <p> tag. The rest is missing. No error message and no other HTML code after this <p>. This is not a PHP issue. When you open this page in Firefox then you can see the error message (When viewing the HTML code). So this is a Chrome issue.

Don't know if there is a workaround somewhere. When this happens to you then you have to test the page in Firefox or check the Apache error log.

Flacon answered 14/5, 2013 at 14:28 Comment(1)
Many thanks for identifying this, I was having the same issue with chrome. But in fact, I also get the problem in Firefox. This line doesn't show errors: <?php foreach ($this->SIL()->eventDateAndPerformanceSelectOptions($event) as $value => $text): ?> in the eventDateAndPerformancesSelectOptions function, but <?php $this->SIL()->eventDateAndPerformanceSelectOptions($event) ?> does. So it does in standard <?php ?> but not within foreach. Tested in both Chrome and Firefox and get the same results. once to watch out for.Constringe
S
1

I had the same problem but I used ini_set('display_errors', '1'); inside the faulty script itself so it never fires on fatal / syntax errors. Finally I solved it by adding this to my .htaccess:

php_value auto_prepend_file /usr/www/{YOUR_PATH}/display_errors.php

display_errors.php:

<?php
ini_set('display_errors', 1);
error_reporting(-1);
?>

By that I was not forced to change the php.ini, use it for specific subfolders and could easily disable it again.

Septarium answered 27/2, 2017 at 2:8 Comment(0)
A
0

I know this thread is old but I just solved a similar problem with my Ubuntu server and thought I would add a note here to help others as this thread was first page in Google for the topic of PHP not displaying errors.

I tried several configuration settings for the error_reporting value in php.ini. From E_ALL | E_STRICT to E_ALL & E_NOTICE and none worked. I was not getting any syntax errors displayed in the browser (which is rather annoying on a development server). After changing the error_reporting setting to "E_ALL" it all started working. Not sure if it is an Ubuntu Oneric specific issue but after restarting Apache errors started showing in the HTML pages the server was serving. Seems the extra options confusing things and all error reporting stops. HTH somone else.

Anastomose answered 11/11, 2011 at 0:36 Comment(1)
I was hoping this was the solution to my problem (I'm on Ubuntu 11.04), but alas, it did not. It's sad when a XAMPP install on Windows has no problems with showing errors, but in PHP's native environment we get nothing. :(Hertz
N
0

I just experienced this same problem and it turned out that my problem was not in the php.ini files, but simply, that I was starting the apache server as a regular user. As soon as i did a "sudo /etc/init.d/apache2 restart", my errors were shown.

Niehaus answered 29/6, 2012 at 13:1 Comment(0)
F
0

I had the same problem with Apache and PHP 5.5. In php.ini, I had the following lines:

error_reporting E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors Off

instead of the following:

error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors=Off

(the =sign was missing)

Fax answered 12/2, 2014 at 10:23 Comment(1)
This connet shoud be to #5527483Fax
B
0

Though this thread is old but still, I feel I should post a good answer from this stackoverflow answer.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

This sure saved me after hours of trying to get things to work. I hope this helps someone.

Bema answered 9/11, 2017 at 10:54 Comment(0)
L
0

When running PHP on windows with ISS there are some configuration settings in ISS that need to be set to prevent generic default pages from being shown.

1) Double click on FastCGISettings, click on PHP then Edit. Set StandardErrorMode to ReturnStdErrLn500.

StandardErrorMode

2) Go the the site, double click on the Error Pages, click on the 500 status, click Edit Feature Settings, Change Error Responses to Detailed Errors, click ok

Change Error Responses to Detailed Errors

Lorola answered 7/2, 2018 at 2:29 Comment(0)
A
0

I have encountered also the problem. Finally I found the solution. I am using UBUNTU 16.04 LTS.

1) Open the /ect/php/7.0/apache2/php.ini file (under the /etc/php one might have different version of PHP but apache2/php.ini will be under the version file), find ERROR HANDLING AND LOGGING section and set the following value {display_error = On, error_reporting = E_ALL}.

NOTE - Under the QUICK REFERENCE section also one can find these values directives but don't change there just change in Section I told.

2) Restart Apache server sudo systemctl restart apache2

Altruist answered 10/4, 2018 at 9:32 Comment(0)
B
0

For me I solved it by deleting the file of php_errors.txt in the relative folder. Then the file is created automatically again when the code runs next time, and with the errors printed this time.

Bathhouse answered 22/10, 2019 at 9:30 Comment(0)
B
0

I also face the same issue, I have the following settings in my php.inni file

display_errors = On
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT

But still, PHP errors are not displaying on the webpage. I just restart my apache server and this problem was fixed.

Bette answered 27/11, 2019 at 12:47 Comment(0)
F
0

I chased this problem for some time with all means and no result.

In the end it turned out that I called a function which was no longer defined as it was transferred to a different file.

This obvious (and hard to find manually) error did not show up anywhere.

Flea answered 4/4 at 21:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.