How do I get PHP errors to display?


I have checked my PHP ini file (php.ini) and display_errors is set and also error reporting is E_ALL. I have restarted my Apache webserver.

I have even put these lines at the top of my script, and it doesn't even catch simple parse errors. For example, I declare variables with a "$" and I don't close statements";". But all my scripts show a blank page on these errors, but I want to actually see the errors in my browser output.

ini_set('display_errors', 1);

What is left to do?

1/16/2020 8:18:28 AM

Accepted Answer

This always works for me:

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

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
5/14/2020 12:32:12 AM

You can't catch parse errors when enabling error output at runtime, because it parses the file before actually executing anything (and since it encounters an error during this, it won't execute anything). You'll need to change the actual server configuration so that display_errors is on and the approriate error_reporting level is used. If you don't have access to php.ini, you may be able to use .htaccess or similar, depending on the server.

This question may provide additional info.


Inside your php.ini:

display_errors = on

Then restart your web server.


To display all errors you need to:

1. Have these lines in the PHP script you're calling from the browser (typically index.php):

ini_set('display_errors', '1');

2.(a) Make sure that this script has no syntax errors


2.(b) Set display_errors = On in your php.ini

Otherwise, it can't even run those 2 lines!

You can check for syntax errors in your script by running (at the command line):

php -l index.php

If you include the script from another PHP script then it will display syntax errors in the included script. For example:


ini_set('display_errors', '1');

// Any syntax errors here will result in a blank screen in the browser

include 'my_script.php';


adjfkj // This syntax error will be displayed in the browser

Some web hosting providers allow you to change PHP parameters in the .htaccess file.

You can add the following line:

php_value display_errors 1

I had the same issue as yours and this solution fixed it.


You might find all of the settings for "error reporting" or "display errors" do not appear to work in PHP 7. That is because error handling has changed. Try this instead:

     // Your code
catch(Error $e) {
    $trace = $e->getTrace();
    echo $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine().' called from '.$trace[0]['file'].' on line '.$trace[0]['line'];

Or, to catch exceptions and errors in one go (this is not backward compatible with PHP 5):

     // Your code
catch(Throwable $e) {
    $trace = $e->getTrace();
    echo $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine().' called from '.$trace[0]['file'].' on line '.$trace[0]['line'];

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]