Wednesday, August 4, 2010

NetBeans and Xdebug

Finally, I was able to setup xdebug with NetBeans.

Client:
Operating System: Windows 7 Enterprise [version: 6.1.7600 ]
Administrator privileges: No
Product Version: NetBeans IDE 6.9 (Build 201006101454)
Java: 1.6.0_21; Java HotSpot(TM) Client VM 17.0-b16

Server:
nginx/0.7.67 - not relevant
Apache/2.2.13 (Unix) with mod_php - not relevant
PHP 5.2.13 (cli) (built: Jul 21 2010 14:56:47)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Steps:
Install Xdebug via PEAR. I got version 2.1.0.

Enable Xdebug extension in php.ini:
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so ; <=- can be different
xdebug.remote_enable = on
xdebug.remote_handler = dbgp
xdebug.remote_host = 2.1.1.11 ; <=- your client ip here
xdebug.remote_port = 9000
xdebug.remote_mode = req
xdebug.idekey = "netbeans-xdebug" ; <=- default netbeans id
xdebug.remote_log = /path/to/your/logs/xdebug.log 
xdebug.extended_info = 1

Check installation in CLI:
php -m | grep xdebug
php -i | grep xdebug 

Restart Apache.

Check firewall settings that "C:\Program Files\NetBeans 6.9\bin\netbeans.exe" is allowed in proper network locations.

Open NetBeans. Go to your project properties > Run Configuration.
Setup "Project URL" and other if need.

Open "Advanced..." settings, check everything there.

I was able to run into debug mode but without execution line highlight.
So I got back to advanced settings of the project, setup path mapping.
Example:
/usr/local/lib/php/Zend > C:\tmp\ZendFramework-1.10.7-minimal\library\Zend

After that, I saw that Zend files were mapped successfully, but part of project files on network storage not. You can see that in a "Call Stack" window.

It turns out, that NetBeans don't likes network in debug mode.
To fix that, open "My Computer" > "Map network drive" to some letter.
Now, use the new drive for path mapping instead of direct network path.

And voila - it works! ;-)

Notes:
By default NetBeans will break on the first line of the script (you can change this behavior in the PHP / General section of the NetBeans Preferences).

Sources:
NetBeans wiki - HowToConfigureXDebug
Path Mapping In PHP Debugger
PHP 5.3 + XDebug + NetBeans + Mac OSX Leopard

See also:
Xdebug - Debugging with multiple users
Be careful with "Ask Every Time" debug URL

Update:
Upgrade to NetBeans 6.9.1 that fixes double ask for debug URL and other improvements.

No comments:

Post a Comment