error-handling error-reporting php syntax-error

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?


  • 10

    I’ve yet to nail down exactly why this works sometimes and not others, but for anyone wanting to quickly toggle errors in a php script (or enable them via a $_REQUEST parameter) these two lines will work most of the time.

    Oct 28, 2013 at 20:15

  • well you can see details of the error by enabling xdebug from php ini file.

    – jewelhuq

    Jan 13, 2016 at 10:14

  • 1

    Most specific editors / IDEs like e.g. Notepad++,Eclipse have builtin syntax check and highlighting, They will show you issues like you described. Please don’t turn on the display of errors on a live system. Hackers will love this, because in most cases paths are shown. You can define error / exeception handler. In this handler you could log the issue and send a mail to the developer, so that he can fix it immediately when an issue occurs. see and

    Dec 10, 2020 at 8:08


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


  • 11

    Also note that you can use these 3 lines, and then include(‘fileImWorkingOn.php’);. Then you can catch the syntax errors too!

    – Snap

    May 8, 2015 at 18:11

  • 18

    While I’m no SysOps, I think more people have an .htaccess file than php.ini, and these would both come before parsing, right? php_flag display_errors 1 for .htaccess

    Jul 9, 2015 at 21:58

  • 3

    E_ALL isn’t sufficient to display all errors in PHP 5.3. “E_STRICT became part of E_ALL in 5.4.0″ – PHP Manual You need E_ALL | E_STRICT or -1 in that version.

    Sep 14, 2016 at 4:12

  • 5

    Man, I’m going to tattoo these three lines

    May 25, 2021 at 22:42

  • 6

    @JuanC.Roldán I literally come back to this answer three times a week.

    – glinda93

    Sep 30, 2021 at 12:45


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.


    • 8

      +①. On my ubuntu /etc/php5/apache2/php.ini

      – m93a

      Feb 23, 2015 at 17:44

    • 7

      for restart (Debian, Ubuntu, etc.) sudo service apache2 restart

      Sep 1, 2015 at 13:04

    • 4

      For restart on OS X sudo apachectl -k restart.

      – Pea

      Jan 10, 2016 at 19:53

    • 3

      fun fact: you can locate your php.ini file loaded if you simply put in phpinfo(); into a blank php file. it’s the 7th row down and called Loaded Configuration File

      Jul 24, 2016 at 4:56

    • This doesn’t work for me. In fact I can call ini_get('display_errors') and it returns an empty string (meaning it is turned off). And yes I checked to make sure it is the only line in the configuration file. The setting is getting overridden somehow and I can’t figure out why and it is driving me nuts. Yes, I’ve searched everything in /etc/php.d/ and it is not one of those files either. Yes, I restarted the web server too. No, there is nothing in the .htaccess file. I’m using PHP 7.4.6.

      – cazort

      Aug 3, 2021 at 18:07