By Abs

2009-06-27 19:09:59 8 Comments

I have checked my PHP init 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?


@Fancy John 2014-01-29 11:25:17

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

@Snap 2015-05-08 18:11:29

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

@Bsienn 2015-06-01 10:35:19

This won't show parse errors

@Ryan Taylor 2015-07-09 21:58:58

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

@Michael 2016-05-17 15:14:28

So now that the errors get logged, where do they go? I went to /var/log/apache2 and it shows all the logs, but there is no information regarding the program I recently ran. I only get information about system restarts once every morning.

@Fancy John 2016-05-18 05:35:24

@Michael The errors go right to the screen or to where the output is redirected to

@Gerard Roche 2016-09-14 04:12:24

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.

@Frank Forte 2016-10-15 00:29:21

For PHP7 this might not be good enough since error handling has changed. See my answer below about catching Errors.

@Angry 84 2016-11-10 05:47:41

Everyone has a PHP.ini, Few have a .htaccess file ... The ability to edit their PHP.ini file is another thing.. And most public servers allow for a custom php.ini file to be used..

@Taron Saribekyan 2016-11-20 06:04:17

Parse errors will be displayed if error not in same file in which you turned on error reporting/displaying. You need to turn on them in first file of your project (f.e. index.php), and all syntax (parse) errors will be displayed (except errors in index.php). Otherwise you must turn on errors displaying in .htaccess (if server support it).

@Angry 84 2017-02-05 23:05:37

As suggested by @Snap that you can show parse errors on included/required files.. Basically have the above 3 lines enabled, then include your file... As long as the base PHP does not have errors, it will show parse errors for the included files. Very handy way to debug is by wrapping your code with a simple index file that only turns on errors and includes a sub file to do all the work.

@BadHorsie 2017-02-27 18:18:34

@RyanTaylor Adding php_flag display_errors 1 to .htaccess doesn't do anything for me on PHP 5.6

@Ryan Taylor 2017-02-27 19:22:06

@BadHorsie there's more than one reason why php might not display error messages, my comment is meant to replace the line ini_set('display_errors', 1); (or extrapolated into anything that uses ini_set).

@Teekin 2017-04-04 15:20:27

This never works for me. Tried it a million times on different systems.

@Teekin 2017-04-08 13:23:08

I really don't understand this. According to php_info(), I have error_reporting on E_ALL, and I have display_error on On, and display_startup_errors on On. Still I never see errors on the web page. I feel like I'm in some alternative universe, where this works for everyone all the time, but never, ever, ever, ever for me, no matter which system I'm using and no matter where I put these settings. In the PHP file, the php.ini, the Apache config files, it doesn't matter. Is really nobody else in the known Universe always having this problem except me?

@user10089632 2018-03-21 14:31:06

Setting the display in php.ini suffices.

@Blaine Lafreniere 2018-05-03 22:49:44

The person asking the question pretty much said display_errors is set in their question, yet they mark this as the correct answer... lol.

@JakubBoucek 2019-03-18 08:18:10

You shloud use string in ini_set function as value parameter, because your version is incompatible with strtict_types mode. Use this instead: ini_set('display_errors', '1');

@Channaveer Hakari 2017-02-01 07:16:23

I would usually go with the following code in my plain PHP projects.


$base_url = null;

if (defined('ENVIRONMENT'))
    switch (ENVIRONMENT)
        case 'DEVELOPMENT':
            $base_url = 'http://localhost/product/';
            ini_set('display_errors', 1);
            ini_set('display_startup_errors', 1);

        case 'PRODUCTION':
            $base_url = 'Production URL'; /* */
            /* Mechanism to log errors */

            exit('The application environment is not set correctly.');

@mohitesachin217 2019-08-29 07:40:20

Other than php.ini and ini_set() function in php script you can do this same thing with .htaccess and httpd.conf directives shown below. Some hosting providers allow set php settings through .htaccess and httpd.conf.

#hide php errors

php_flag display_startup_errors ON

php_flag display_errors ON

php_flag html_errors ON

php_flag log_errors on

php_flag ignore_repeated_errors off

php_flag ignore_repeated_source off

php_flag report_memleaks on

php_flag track_errors on

php_value docref_root 0

php_value docref_ext 0

php_value error_log /home/path/public_html/domain/PHP_errors.log

php_value error_reporting 999999999

php_value error_reporting -1

php_value log_errors_max_len 0

Order allow,deny

Deny from all

Satisfy All

@Muhammad Adeel Malik 2019-04-11 08:43:10

You can do this by changing the php.ini file and add the following

display_errors = on
display_startup_errors = on

OR you can also use the following code as this always works for me

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

@Peter Mortensen 2019-06-27 12:24:08

PHP.ini or php.ini?

@Peter Mortensen 2019-06-27 12:24:48

"**strong text**"??

@pardeep 2018-05-24 08:48:07

    // Turn off error reporting

    // Report runtime errors
    error_reporting(E_ERROR | E_WARNING | E_PARSE);

    // Report all errors

    // Same as error_reporting(E_ALL);
    ini_set("error_reporting", E_ALL);

    // Report all errors except E_NOTICE
    error_reporting(E_ALL & ~E_NOTICE);

While your site is live, the php.ini file should have display_errors disabled for security reasons. However, for the development environment, display_errors can be enabled for troubleshooting.

@user8031209 2019-03-28 12:42:07

You might want to use this code:

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

@Kalhua 2013-05-18 15:01:34

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.

@PeterM 2015-10-27 18:45:04

Not php_flag? ie.: php_flag display_errors on

@posfan12 2016-12-23 14:34:21

I tried this and got 500 Internal Server Error.

@Lazaros Kosmidis 2018-10-09 07:25:14

And if you are in nginx environment then add the php value to your site (sites-available) configuration under the location ~\.php directive. fastcgi_param PHP_VALUE " error_reporting=E_ALL;\n display_errors=1;";

@Binit Ghetiya 2017-02-01 07:33:23

You can do something like below:

Set the below parameters in your main index file:

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

Then based on your requirement you can choose which you want to show:

For all errors, warnings and notices:

    error_reporting(E_ALL); OR error_reporting(-1);

For all errors:


For all warnings:


For all notices:


For more information, check here.

@Peter Mortensen 2019-02-17 09:26:38

What is the "main index file"? File index.html?

@Binit Ghetiya 2019-02-18 10:42:57

index.php file will have this code

@Xakiru 2017-03-27 02:31:01

The best/easy/fast solution that you can use if it's a quick debugging, is to surround your code with catching exceptions. That's what I'm doing when I want to check something fast in production.

try {
    // Page code
catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";

@Frank Forte 2017-08-19 02:58:11

For php7, catch (Throwable $e) is better... Or another catch block underneath catch(Error $e)

@Salam 2017-04-27 16:29:49

That's what I learnt. In the PHP.INI file,

error_reporting = E_ALL
display_errors = On

@Peter Mortensen 2019-02-17 09:22:55

Changing in? Adding to?

@Wembo Mulumba 2017-05-09 03:28:31

This code on top should work:


However, try to edit the code on the phone in the file:

error_reporting =on

@Peter 2017-05-20 12:07:56

As we are now running PHP 7, answers given here are not correct any more. The only one still OK is the one from Frank Forte, as he talks about PHP 7.

On the other side, rather than trying to catch errors with a try/catch you can use a trick: use include.

Here three pieces of code:

File: tst1.php

    ini_set('display_errors', 'On');
    // Missing " and ;
    echo "Testing

Running this in PHP 7 will show nothing.

Now, try this:

File: tst2.php

    ini_set('display_errors', 'On');
    include ("tst3.php");

File: tst3.php

    // Missing " and ;
    echo "Testing

Now run tst2 which sets the error reporting, and then include tst3. You will see:

Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in tst3.php on line 4

@lintabá 2017-06-04 14:41:28

You can add your own custom error handler, which can provide extra debug information. Furthermore, you can set it up to send you the information via email.

function ERR_HANDLER($errno, $errstr, $errfile, $errline){
    $msg = "<b>Something bad happened.</b> [$errno] $errstr <br><br>
    <b>File:</b> $errfile <br>
    <b>Line:</b> $errline <br>
    <pre>".json_encode(debug_backtrace(), JSON_PRETTY_PRINT)."</pre> <br>";

    echo $msg;

    return false;

function EXC_HANDLER($exception){
    ERR_HANDLER(0, $exception->getMessage(), $exception->getFile(), $exception->getLine());

function shutDownFunction() {
    $error = error_get_last();
    if ($error["type"] == 1) {
        ERR_HANDLER($error["type"], $error["message"], $error["file"], $error["line"]);

set_error_handler ("ERR_HANDLER", E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);

@Sumit Gupta 2017-09-26 12:32:51

Set this in your index.php file:

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

@Peter Haberkorn 2017-10-19 05:45:41

If you have Xdebug installed you can override every setting by setting:

xdebug.force_display_errors = 1;
xdebug.force_error_reporting = -1;


Type: int, Default value: 0, Introduced in Xdebug >= 2.3 If this setting is set to 1 then errors will always be displayed, no matter what the setting of PHP's display_errors is.


Type: int, Default value: 0, Introduced in Xdebug >= 2.3 This setting is a bitmask, like error_reporting. This bitmask will be logically ORed with the bitmask represented by error_reporting to dermine which errors should be displayed. This setting can only be made in php.ini and allows you to force certain errors from being shown no matter what an application does with ini_set().

@andre 2014-01-29 09:52:43

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

@jxmallett 2015-04-24 02:55:34

If, despite following all of the above answers (or you can't edit your php.ini file), you still can't get an error message, try making a new PHP file that enables error reporting and then include the problem file. eg:

ini_set('display_errors', 1);

Despite having everything set properly in my php.ini file, this was the only way I could catch a namespace error. My exact scenario was:

namespace a\b;
class x {

namespace c\d;
use c\d\x; //Dies because it's not sure which 'x' class to use
class x {

@peterh 2018-07-17 13:32:22

No, the error reporting is not a loglevel, it is a bitfield. Using 999999 is a very bad idea, use some power-of-two minus 1, for example 2047!

@jxmallett 2018-07-18 02:52:12

You're absolutely right, @peterh! I've changed it to E_ALL as this will enable reporting of all errors (except strict errors in php 5.4 and below).

@Frank Forte 2016-03-28 19:26:51

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'];

@Fancy John 2016-10-17 05:55:15

It would be nice to show the traceback as well

@vdegenne 2017-01-22 11:22:11

Do you mean PHP7 or PHP7.1 ? I am confused, I tried as the validated answer proposed and it works, I think you are proposing something a bit different IMHO, indeed "no backward compatibility" and if you have to modify a full PHP < 7 code and need to add try{} catch() {} code everywhere in your already defined php code, I don't even want to think the mess that's going to be..

@Frank Forte 2017-03-23 03:25:31

@FancyJohn, this could help: $bt = debug_backtrace(); print_r($bt);.

@Frank Forte 2017-03-23 03:28:52

@ballangddang, I ran into the issue with PHP 7.0, where the only way I could get the error to display was using the try/catch blocks and specifically catching Error. If you rewrite all requests (except maybe JavaScript, CSS, Images, etc) to the index.php file, then have the try catch block there, it makes it easier. Yes, any system that does not have a single entry point would be a major headache to update.

@Martin Tournoij 2017-06-05 02:20:28

Does PHP not show unhandled exceptions? Pretty sure it does?

@Frank Forte 2017-08-19 03:04:27

It should show unhandled exceptions. If you turn on an output buffer at the start (so that you can send headers at any point before finally flushing the response body) maybe the exception message can get lost somewhere.

@Paul Spiegel 2019-02-05 14:54:44

This looks like a bad idea. Time to use (or write) a global exception handler.

@Frank Forte 2019-02-07 13:11:07

@PaulSpiegel, which part is s bad idea? Try/catch blocks? Output buffering mentioned in my previous comment? Each serves a purpose. For example, the try/catch allows you to take a different course if something goes wrong, without adding a big application inside the exception handler. The output buffering allows for server side caching.

@Paul Spiegel 2019-02-07 13:21:30

I mean try/catch block to show exceptions. Why don't you just use set_exception_handler? This way you could separate it from your code.

@Frank Forte 2019-02-08 19:05:23

So you can handle different exceptions in different ways, depending how critical the exception or error is in your program.

@jewelhuq 2017-01-13 18:56:39

Just write:


@Abhijit Jagtap 2016-05-04 19:14:09


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

This is the best way to write it, but a syntax error gives blank output, so use the console to check for syntax errors. The best way to debug PHP code is to use the console; run the following:

php -l phpfilename.php

@B.Balamanigandan 2016-01-11 12:37:40

Here is a PHP script:

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

    /* Reports for either E_ERROR | E_WARNING | E_NOTICE  | Any Error*/

    echo(abc); /* Notice: abc is an undefined constant */

For a more detailed explanation of PHP errors, visit PHP Error - error_reporting().

@cpburnz 2016-05-14 16:22:12

How is this any different from Fancy John's answer?

@B.Balamanigandan 2019-06-12 05:13:22

@cpburnz - Its a straight forward questions, every one given the same set of codes in their flavor that the only difference. I given additional a URL link that will give more information about the PHP error.

@NavyaKumar 2015-03-31 18:38:47

Create a file called php.ini in the folder where your PHP file resides.

Inside php.ini add the following code (I am giving an simple error showing code):

display_errors = on

display_startup_errors = on

@Lead Developer 2014-05-05 13:23:31

This will work:

     ini_set('display_errors', 1);    

@chiborg 2016-01-11 12:11:27

If you somehow find yourself in a situation where you can't modifiy the setting via php.ini or .htaccess you're out of luck for displaying errors when your PHP scripts contain parse errors. You'd then have to resolve to linting the files on the command line like this:

find . -name '*.php' -type f -print0 | xargs -0 -n1 -P8 php -l | grep -v "No syntax errors"

If your host is so locked down that it does not allow changing the value via php.ini or .htaccess, it may also disallow changing the value via ini_set. You can check that with the following PHP script:

if( !ini_set( 'display_errors', 1 ) ) {
  echo "display_errors cannot be set.";
} else {
  echo "changing display_errors via script is possible.";

@scones 2017-11-24 13:27:54

find . -name '*.php' -type f -exec php -l {} \; | grep -v 'No syntax errors detected' is simpler

@mike 2014-01-28 15:41:05

When using PHP as an Apache module, we can a change the configuration settings using directives in Apache configuration files (e.g. httpd.conf) and .htaccess files. You will need “AllowOverride Options” or “AllowOverride All” privileges to do so.

Check this

@user1803477 2013-01-08 09:27:35

Inside your php.ini:

display_errors = on

Then restart your web server.

@Shanimal 2013-04-01 03:48:29

+1. On my mac : /etc/php.ini

@m93a 2015-02-23 17:44:10

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

@Peter Krauss 2015-09-01 13:04:26

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

@Pea 2016-01-10 19:53:17

For restart on OS X sudo apachectl -k restart.

@Frankenmint 2016-07-24 04:56:50

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

@arqam 2016-08-29 07:08:41

How can we do if we are writing the php code direclty on the cPanel?

@Michael Madsen 2009-06-27 19:14:17

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.

@Abs 2009-06-27 19:16:52

Did not know that. I edited the php.ini file manually and it is working now. Thanks!

Related Questions

Sponsored Content

16 Answered Questions

[SOLVED] Why shouldn't I use mysql_* functions in PHP?

  • 2012-10-12 13:18:39
  • Madara Uchiha
  • 208360 View
  • 2405 Score
  • 16 Answer
  • Tags:   php mysql database

37 Answered Questions

[SOLVED] Deleting an element from an array in PHP

  • 2008-12-15 20:28:55
  • Ben
  • 2377727 View
  • 2316 Score
  • 37 Answer
  • Tags:   php arrays unset

32 Answered Questions

[SOLVED] How do I get a YouTube video thumbnail from the YouTube API?

18 Answered Questions

[SOLVED] Reference — What does this symbol mean in PHP?

17 Answered Questions

[SOLVED] PHP parse/syntax errors; and how to solve them?

28 Answered Questions

[SOLVED] How can I prevent SQL injection in PHP?

7 Answered Questions

[SOLVED] How does PHP 'foreach' actually work?

30 Answered Questions

[SOLVED] How do you parse and process HTML/XML in PHP?

2 Answered Questions

[SOLVED] PHP Doesn't Display Errors or Warnings

  • 2010-03-26 20:35:25
  • Dustin Sun
  • 1940 View
  • 8 Score
  • 2 Answer
  • Tags:   php

Sponsored Content