OS X上的xdebug部分工作(例如,在终端中打印堆栈跟踪但不在浏览器中打印)。

I'm trying to get xdebug working on my Mac. I'm using OS 10.6 with the built-in versions of Apache (2.2.1) and PHP (5.3.8). I followed the "tailored installation instructions" on the xdebug website, which basically consisted of these steps:

  1. Build xdebug (version 2.1.3) from source
  2. Move xdebug.so to /usr/lib/php/extensions/no-debug-non-zts-20090626
  3. Add to php.ini: zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
  4. Restart the webserver.

From what I understand, that should be it. I know most people use xdebug with an IDE like PHPEclipse, but it doesn't sound like that's necessary just to get debugging output on the page. And a lot of old instructions involve installing MAMP, but it looks like that's no longer necessary.

Signs xdebug is working: When I run php -m and phpinfo() I get the expected information on xdebug. In scripts I'm able to call functions like xdebug_is_enabled() (returns 1) and xdebug_get_function_stack() (returns the stack).

Ways xdebug is not working: The main reason I installed xdebug was to get a stack trace when there's an error, and that's not happening. According to this documentation page, I should get a stack trace as long as display_errors is set to On in php.ini, (which it is). I've tried code that should evoke a warning (e.g., echo(hello)) as well as code that produces a fatal error (e.g., $x->awesomefunction() when $x isn't an object). Neither one produces any xdebug output, and the fatal error just causes the page to die silently. The test code given in the documentation I linked to also produces nothing.

UPDATE: It turns out that if I run a script with a fatal error from the terminal, I do get a stack trace from xdebug. However, it's still not showing up when I run the script from a browser

Also, regular error reporting is now broken: Previously, I'd get error output by including the commands:

ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);

Now, putting those lines in my script doesn't produce any error reporting either. (in the browser. It does cause errors to be shown when I run the script from the terminal.)

So, what's wrong here? Did I leave something out of the xcode installation? Do I have a setting hanging around somewhere else on my system, suppressing errors? I've tried everything I can think of, but I'd be happy to test any ideas you have.

After several more hours of thrashing, I discovered that one of my test files actually was including another file that set display_errors to 0. The other test file was straight off of the xdebug site, but I think that at the time I was using it I'd introduced some other config error that prevented it from working properly. I'm truly embarrassed! Let this be today's object lesson in the importance of systematic, repeatable tests during debugging. On the bright side, xdebug is now working like a peach.

To summarize, the series of steps that worked was:

  1. Build xdebug (version 2.1.3) from source
  2. Move xdebug.so to /usr/lib/php/extensions/no-debug-non-zts-20090626
  3. Add to php.ini: zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
  4. Add to php.ini: display_errors = On
  5. Restart the webserver.

If it is working on console and not on browser, it's probably a xdebug configuration issue.

I'm not a Mac user, but on Ubuntu there are 2 different php.ini files, one for console and one for apache. If that's the case for Mac also, you can check if xdebug is enabled and properly set up in both php.ini files.

Also you can check the xdebug settings mentioned in the guide.