WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to get PHP Errors to Display

Topic: PHP / MySQLPrev|Next

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.


Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties