Q:

How to get PHP Errors to Display

0

How to get PHP Errors to Display

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the ini_set() Function

For security reasons, error display in production environments is disabled by default.

But, if you want to display errors in a PHP file for debugging purposes, you can place these lines of code at the top of your PHP file, as shown in the following example:

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

// Rest of code here...
?>

However, this doesn't make PHP to show parse errors (such as missing semicolon). The only way to show those errors is to set the display_errors directive to On in php.ini file. By default display_errors set to Off for production environments.

display_errors = On

After modifying the php.ini file restart your web server, or php-fpm service if you are using PHP-FPM.

However, if you don't have access to php.ini file—for instance, if you're using a shared hosting—then putting the following line in .htaccess file might also work.

php_flag display_errors 1
 

Warning: Outputting errors in production environments could be very dangerous. Sensitive information could potentially leak out of your application such as database usernames and passwords or worse. For production environments, logging errors is recommended.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
<< How to Return JSON from a PHP Script...