Php – Configure XDebug for PHP

netbeansPHPxdebug

I want to debug PHP from NetBeans 7.1. My web server is IIS.
I've first of all discovered that NetBeans tries to use XDebug, downloaded it, copied DLL to appropriate folder. Now I would like to know how to configure it properly.

The online php config analyser gave me following advices:

  1. Download php_xdebug-2.1.4-5.3-vc9-nts.dll
  2. Move the downloaded file to C:\Program Files\PHP\v5.3\ext
  3. Edit C:\Program Files\PHP\v5.3\php.ini and add the line
  4. zend_extension = C:\Program Files\PHP\v5.3\ext\php_xdebug-2.1.4-5.3-vc9-nts.dll

Restart the webserver

Ok, everything is clear, except in which section of php.ini to put the line. I'm in doubt.

On the other side, Netbeans complains:

No connection from xdebug was detected within 224 seconds. The reasons
could be that xdebug is not installed or not properly configured. Be
sure that your php.ini file contains these entries:

xdebug.remote_enable=on

xdebug.remote_handler=dbgp

xdebug.remote_host=localhost (or hostname)

xdebug.remote_port=9000

And again, in which section of php.ini to put these lines?

Best Answer

You can add xdebug lines anywhere to the php ini file most likely at the end. To check if xdebug is correctly installed check phpinfo function and the debugclient. You can get the debugclient at the xdebug homepage: http://xdebug.org/docs/install. When you start it with the switches -i 9000 -r 9000 it should connect to xdebug after then you can verify it with netstat -an | grep 9000. Then you can load an example webpage and look at the output of the debugclient. Just in case check your xdebug log. When it works with the debugclient you have a good proof and you can make it work with your IDE. This help me a lot: http://forums.netbeans.org/topic1513-30.html. You can also check this script if the xdebug is listen to port 9000:

<?php 
     $address = '127.0.0.1'; 
     $port = 9000; 
     $sock = socket_create(AF_INET, SOCK_STREAM, 0); 
     socket_bind($sock, $address, $port) or die('Unable to bind'); 
     socket_listen($sock); 
     $client = socket_accept($sock); 
     echo "connection established: $client"; 
     socket_close($client); 
     socket_close($sock); 
?>

It didn't work for me but give it a try? I've lighttpd and xdebug on my virtual machine and I use a reverse shell with my remote server. I use Komodo IDE.