How to Get PHP Errors to Display

How do I get PHP errors to display?

This always works for me:

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

However, this doesn't make PHP to show parse errors - the only way to show those errors is to modify your php.ini with this line:

display_errors = on

(if you don't have access to php.ini, then putting this line in .htaccess might work too):

php_flag display_errors 1

Showing all errors and warnings

Display errors could be turned off in the php.ini or your Apache configuration file.

You can turn it on in the script:

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

You should see the same messages in the PHP error log.

How can I get useful error messages in PHP?

For syntax errors, you need to enable error display in the php.ini. By default these are turned off because you don't want a "customer" seeing the error messages. Check this page in the PHP documentation for information on the 2 directives: error_reporting and display_errors. display_errors is probably the one you want to change. If you can't modify the php.ini, you can also add the following lines to an .htaccess file:

php_flag  display_errors        on
php_value error_reporting 2039

You may want to consider using the value of E_ALL (as mentioned by Gumbo) for your version of PHP for error_reporting to get all of the errors. more info

3 other items: (1) You can check the error log file as it will have all of the errors (unless logging has been disabled). (2) Adding the following 2 lines will help you debug errors that are not syntax errors:

error_reporting(-1);
ini_set('display_errors', 'On');

(3) Another option is to use an editor that checks for errors when you type, such as PhpEd. PhpEd also comes with a debugger which can provide more detailed information. (The PhpEd debugger is very similar to xdebug and integrates directly into the editor so you use 1 program to do everything.)

Cartman's link is also very good: http://www.ibm.com/developerworks/library/os-debug/

PHP error_reporting vs. display_errors

They are NOT the same, but in your use may have the same outcome.

  1. error_reporting is the level of reporting, NONE through ALL. This determines what types of errors are reported (E_NOTICE, E_WARNING, E_ALL, etc..).

  2. display_errors is whether to display those errors (output to browser, CLI, etc...) that are reported from 1.

If you set error_reporting(E_ALL) and ini_set('display_errors', '0') you can still get all errors reported in the log file but not displayed.

With error_reporting(0) you don't get any errors displayed or in the log and it doesn't matter the values of display_errors.

display_errors should be off in your production applications, preferably in php.ini so that information such as file paths, database names and usernames are not shown. Error reporting sent to the log is beneficial and should not be a security concern.

How can I make PHP display the error instead of giving me 500 Internal Server Error

Check the error_reporting, display_errors and display_startup_errors settings in your php.ini file. They should be set to E_ALL and "On" respectively (though you should not use display_errors on a production server, so disable this and use log_errors instead if/when you deploy it). You can also change these settings (except display_startup_errors) at the very beginning of your script to set them at runtime (though you may not catch all errors this way):

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

After that, restart server.

Turn off display errors using file php.ini

I always use something like this in a configuration file:

// Toggle this to change the setting
define('DEBUG', true);

// You want all errors to be triggered
error_reporting(E_ALL);

if(DEBUG == true)
{
// You're developing, so you want all errors to be shown
display_errors(true);

// Logging is usually overkill during development
log_errors(false);
}
else
{
// You don't want to display errors on a production environment
display_errors(false);

// You definitely want to log any occurring
log_errors(true);
}

This allows easy toggling between debug settings. You can improve this further by checking on which server the code is running (development, test, acceptance, and production) and change your settings accordingly.

Note that no errors will be logged if error_reporting is set to 0, as cleverly remarked by Korri.

Display PHP Errors in IIS

IF you set custom error to Detailed in feature settings of error pages for website and server both

AND if in your php.ini file you set the display_errors = on & error_reporting = E_ALL

THEN there is only one possibility for getting [IIS default 500 error page] is that "Your PHP is not working coz of miss configuration."

The required configurations are:

After setting Handler Mappings to your php-cgi.exe file(which is in you php installation dir) as FastCGI, open the php.ini file and edit following lines OR add if not found in file. (if php.ini is not exists in you PHP installation dir then rename from existing php.ini-development OR php.ini-production)

1) extension_dir = "ext\"

;ext folder will be in PHP installation, if not create and don't forget ending \

2) log_errors = On

3) error_log = "C:\inetpub\temp\php-errors.log"

4) cgi.force_redirect = 0

; may be you need to add this line add it anywhere, for instance-before '; File Uploads ;'

5) cgi.fix_pathinfo = 1

6) fastcgi.impersonate = 1

7) fastcgi.logging = 0

 Be careful and there should not `;` before any of these lines.

see documentation - installing/configuring PHP

Even after correct configurations PHP may not work because of system corruption. You can check by double click on php-cgi.exe and php-win.exe it should run without proper error (other then warnings OR ext/fileName... is missing messages - these are OK).

Note: after these many other setting are requires to run all things of php (ex. session), but by these SIMPLE PHP WILL WORK or PHP will properly show the error for what's wrong (NOT 500 page).

How to show errors in php on ubuntu?

Check for the "loaded configuration file" in php.ini. If it is the same file then there must be some duplicate "display_errors = Off" line in your php.ini file in your bottom part. The later lines are always taken for execution. So search for all "display_errors" in your php.ini file and remove duplicates. And restart apache. Check phpinfo() output again to find about the "error reporting" variables.

php error reporting for single page?

Using error_reporting(E_ALL) will enable error reporting for only that page!

To display errors use, ini_set("display_errors", 1)



Related Topics



Leave a reply



Submit