PHP Errors are not showing up in the browser - php

I am facing a strange problem. I have set up everything in php.ini file. But i can't get any errors showing up in the browser. I googled to set up the .ini file and did all the required things. But still i am not able to get error message displaying in the browser. My PHP ini settings,
display_errors = On
display_startup_errors = On
error_reporting = E_ALL | E_STRICT
log_errors = On
track_errors = On
I tried with the following code to see error message,
<?php
require_once("sample.php");
?>
Actually the file sample is not available. So it must show Fatal error. But it is showing a blank page.
Can you point me out to fix this? I don't know what i am missing here.

You can also add custom error reporting to your php and test with that:
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
require_once( "sample.php" );
?>
If you get fatals, then something is wrong with php.ini configuration ( maybe you have multiple php.ini files? ). If you still get nothing, then php can find the file ( maybe you have some redirects set up? Maybe some strange extensions? )

I found the problem. Actually, PHP is installed with XDebug extension. So the problem is in that extension. Even i was not aware of that. Because this system was used by someone previously. I uninstalled and installed again with new supported version. It works now. Thanks and sorry for the inconvenience friends.

Try finding these words in your php.ini file
display_errors
error_reporting
change default value of display_errors from Off to On
change default value of error_reporting from XXXX to E_ERROR | E_PARSE
Restart apache server.
Mind, It'll always show errors.

I know its an old thread , yet if someone is facing the same issue with php8 installation , use the following methods .
<?php
phpinfo()
?>`
and you can find the location of php.ini in the phpinfo() page , php8 when i installed i had three directories inside /etc/php/ location 7.2 , 8.0 , 8.1 .I was using ubuntu 18.04. Run this command to find php.ini location php -i | grep "php.ini" .Try editing the php.ini in the shown location and if it does not work , follow phpinfo() page and find the php.ini location in the page.
if you have added the following script
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
require_once("sample.php");
?>
and you are able to see the error means something is overriding the php.ini.
Most likely in that case php.ini file location may be different. You might have edited the wrong php.ini file.I had to edit php.ini file in this location /etc/php/8.0/apache2. Change display_errors directive to on in the php.ini file.

Related

PHP5 - show errors

SOLUTION:
Bunyamin's comment was my solution.
display_errors for php5-fpm not working with nginx
The second answer of that question mentioned the /etc/php5/fpm/pool.d/*.conf files, in my case /etc/php5/fpm/pool.d/www.conf
There I added
php_flag[display_errors] = on
and now it works.
QUESTION:
I have already turned on error reporting in the /etc/php5/cgi/php.ini file and no errors are shown.
If I add
error_reporting(E_ALL);
ini_set('display_errors', 1);
to my PHP code, all the errors are shown.
Why doesn't it work if I turn on error reporting in the php.ini files and don't add that code snippet? Shouldn't the php.ini file do the same as the code?
Webserver: Lighttpd
OS: Raspbian Jessie
EDIT:
phpinfo() shows that display_errors is set to Off, but in the php.ini file its turned On.
My php.ini file: http://pastebin.com/1qeK310n
Output of phpinfo(): http://www.file-upload.net/download-11264468/phpinfo.htm.html
I have four suggestions.
First of all, make sure that you are editing the correct php.ini file. You can see which php.ini file is used with the function phpinfo().
Simply create a file, phpinfo.php, with the following content. When you load the page (http://yoursite.com/phpinfo.php), you can see the details about your PHP configuration.
<?php
echo phpinfo();
Secondly, make sure you set error_reporting to E_ALL to get full debug information (Suggested only in development).
Thirdly, is there anywhere in your application that you set display_errors to 0. Sometimes, especially in frameworks, this property is set to 0.
Lastly, sometimes Apache is configured in a way that a custom php.ini file located in the root directory of your webpage can override your global configuration. Then the change in global php.ini file would not affect your application.
You have to scroll down to where the display_errors is set to OFF an then turn it on (Don't uncomment and set to on, scroll down)

PHP errors in a new MAMP

I download absolutely new, the last version of MAMP 3.5.
I go to phpInfo and it says the PHP version is 7.0.0 and Configuration File (php.ini) Path is: /Applications/MAMP/bin/php/php7.0.0/conf.
I go to php.ini in that path and change errors to on: display_errors = On. I check that: error_reporting = E_ALL.
I Stop Servers and Start Servers. I reload the page in the browser. I check phpInfo and now display_errors is on.
I do not see the errors.
I have checked all the solutions in the web, just to name a few:
MAMP Config help, display PHP errors
Why MAMP doesn't display errors?
how to display errors on MAMP?
I tried everything and I do not see PHP errors. What else can I do?
Preface your PHP code with this. It will force error display.
ini_set('display_errors', 'On');
error_reporting(E_ALL);
Also check your .ini files in the following locations:
Applications/MAMP/bin/php/(PHP version)/conf/php.ini
Applications/MAMP/conf/php/(PHP version)/conf/php.ini
They should both be set for:
display_errors = On
EDIT: I should clarify this, as it may be a point of confusion: You should restart your MAMP server when the changes are complete.
I changed my .ini files located as Bangkoian stated above. In MAMP PRO 3.5 there is an additional or third .ini file that needs to be changed.
This file can only be accessed through the MAMP Pro File menu . I'm not sure where it actually is in the actual file structure.
Access the .ini by: Command +4 or
File > Edit Template > PHP > Version Your using
Find around line 271:
error_reporting = MAMP_error_reporting_MAMP
and change to E_ALL
error_reporting = E_ALL
under error_reporting look for display_errors and change:
display_errors = MAMP_display_errors_MAMP
and change to On
display_errors = On
You'll end up needing to change these line in 3 Different places
Applications/MAMP/bin/php/(PHP version)/conf/php.ini
Applications/MAMP/conf/php/(PHP version)/conf/php.ini
and through MAMP Pro itself:
Command +4 or
File > Edit Template > PHP > Version Your using
After the third method was added it worked as expected, I'm also using PHP 7. Make sure Debugger Activate Xdebug it checked under the PHP tab.

PHP won't display any errors

I have a PHP page that's erroring out somewhere (it loads blank white, no title or anything), but I cannot for the life of me get it to display errors. I have the following in my files, but the page still loads blank white. What can I do to get PHP to display errors? This is on PHP 5.5 on my own server, and I am editing the correct php.ini file (according to phpinfo()).
php.ini:
display_errors = on
error_reporting = E_ALL
.htaccess:
php_value error_reporting -1
Specific file in question:
ini_set('display_errors',1);
error_reporting(E_ALL);
Make sure to add it to the correct php.ini file. Some web hosters have configured their server such that a php.ini in the same directory as the html of php file will be executed. But this is not the default. If you are in Linux, try putting it into /etc/php5/apache2/php.ini or search on your harddisk for any php.ini.
Turns out display_errors was already set below my own edits, so php.ini was using the default value of Off instead of my value. Deleted my edits and fixed the spots that needed it, problem resolved.

PHP not displaying errors even though display_errors = On

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.
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.
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.
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
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.
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
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
Make sure the php.ini that you're modifying is on the /etc/php5/apache2 folder, or else it won't have any efect...
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>
test
</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.
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.
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
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.
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.
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)
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.
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
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.
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.

MAMP Config help, display PHP errors

I am running the latest version of MAMP on Snow Leopard.
My php.ini file has been configured to display errors. display_errors = on. The phpinfo(); page displays the status of error reporting, it is on. I have restarted my web server several times.
I've searched through Google, and I cannot find any similar problem. Everyone just says to do exactly what I have done, but it is not working. The pages will just remain blank, (with no reporting), if I intentionally place errors.
Any thoughts as to what the problem may be?
For any future posters who run into this issue...
I was having the same issue and found that I was making changes to the wrong php.ini files. Run phpinfo and find the path to the active php.ini file to make sure you're editing the correct one.
On my installation of mamp there were multiple instances of the /conf directory with php.ini files. The php.ini files I needed were located in the /bin/php/php[version#]/conf directory and not the MAMP/conf directory.
Exact path to the php.ini file I needed to edit:
Applications/MAMP/bin/php/php5.4.10/conf/php.ini
Change display_errors = Off to display_errors = On
In addition to the display_errors directive, which has to be set to On, you might have to configure error_reporting.
For instance, you can use this in your php.ini file :
error_reporting = E_ALL
Another should, useful to test, might be to place this kind of portion of PHP code at the beginning of your script :
error_reporting(E_ALL);
ini_set('display_errors', 'On');
This is useful when you don't have access to php.ini and/or just want to test quickly, without having to restart the webserver.
As a sidenote, when it comes to displaying errors, the Xdebug extension is really great : when it's installed/enabled/configured, instead of just having an error message, you'll get the full stack-trace, which is much more useful ;-)
I recently experienced the same problem - in my case I had downloaded a client's Wordpress site from their live server that turned out to have been tampered with by malicious script insertion that was overriding the error reporting in order to escape detection.
A little late to help the OP(!), but perhaps of use to future searchers.
There might have a .htaccess file in a directory that overrides the display_errors setting set in php.ini. From your post I assume you didn't explicitly add this but a few frameworks do this by default so might be added that way. Look for a line like this in your .htaccess file:
php_value display_errors 0
and change the value to 1.
If you have several php sdks with several versions, first make it sure you are editing correct php.ini file. If you were right add this two lines at the beginning of the code.
error_reporting(E_ALL);
ini_set('display_errors', 'On'); // or ini_set('display_errors', 1);
Here's a twist to the same answer. I had the same issues, just copied and pasted the ini path from the php info page and still same problems...
turns out I made a syntax mistake when I edited my 'error_reporting' block in the php.ini.
I had E_NOTICE rather than ~E_NOTICE.
:(
So mistakes can happen in the php.ini if you were editing it and totally forgot you edited something.

Categories