How I set up remote debugging (xdebug) with Netbeans.

This setup allows you to step through php code, including looking at variable values, that’s running on a remote server….

  1. Downloaded and installed JDK (1.6.25)
  2. Downloaded and installed the Netbeans 7.0 PHP bundle
  3. Tried and failed to install xdebug on my 1and1 managed linux server
    1. Logged in using putty to ssh
    2. At the command line, ran “pecl xdebug”
    3. Discovered that I don’t have sufficient rights for PECL operation, and xdebug seems not to be already installed
    4. Installed xdebug on Titan  (Windows XP Pro machine, with a WAMP5 server)
      1. Checked which version of xdebug would be right for my Titan WAMP5 installation, using xdebug wizard, at:
        http://xdebug.org/find-binary.php
      2. Pointed my browser at titan
      3. Clicked on phpinfo
      4. Scraped the webpage, put it into the wizard, which told me to use:
        == php_xdebug-2.1.1-5.2-vc6.dll
      5. Followed the wizard instructions:

i.      Download php_xdebug-2.1.1-5.2-vc6.dll

ii.      Move the downloaded file to c:\wamp\php\ext
iii.      Edit C:\wamp\Apache2\bin\php.ini and add the line:

zend_extension_ts = c:\wamp\php\ext\php_xdebug-2.1.1-5.2-vc6.dll

iv.      Enable xdebug in C:\wamp\Apache2\bin\php.ini

zend_extension_ts = “c:\wamp\php\ext\php_xdebug-2.1.1-5.2-vc6.dll”

[XDebug]

xdebug.remote_enable=1

xdebug.remote_host=”localhost”

xdebug.remote_port=9000

xdebug.remote_handler=dbgp

v.      These settings will enable xdebug, cause it to try to attach to a debug client on the local machine at port 9000 using the DBGp protocol

vi.      Note that these settings do NOT need to be put into the website’s root directory, they affect xdebug for the entire Apache installation.

vii.      Restart the Apache webserver

  1. Installed XDebugClient (xdc.exe) on Titan to test the xdebug installation there locally
    1. Downloaded 1.0 beta5 from http://code.google.com/p/xdebugclient/
    2. Placed it on Titan in Program Files, made a shortcut on taskbar.  (no installer is provided, just put it somewhere and run it)
    3. It’s default is already port 9000.
    4. Created a simple dbgtest.php file in a xdebug-tests subdir of the www doc root of server (/www/xdebug-tests), containing the following code:

<?php

$a=1;

$b=2;

$c=$a+$b;

echo “a+b=$c”;

?>

  1. Started the XDebugClient, set it to Debug-Listen
  2. Pointed my browser at:

http://localhost/xdebug-tests/dbgtest.php?XDEBUG_SESSION_START=mysession.com

  1. The purpose of the parameter is to make xdebug issue a cookie with a longer browser session timeout.
  2. You can change that cookie’s expiration duration (default is 1 hr) using the php.ini setting:

xdebug.remote_cookie_expire_time = 3600

  1. see http://www.xdebug.org/docs/remote#browser_session for more info
  2. Observed the PHP source code appear in XDebugClient
    1. Observed the browser progress bar waiting without progress
    2. Did Debug-Run in the XDebugClient
    3. Observed the browser paint the result of the php code.
    4. Installed XDebugClient on a laptop (Mercury, a different machine than Titan, but on the same LAN segment)
      1. Changed Titan’s apache php.ini file to use the IP address of Mercury

xdebug.remote_host=”localhost”

  1. Repeated steps 7-9 above using a browser and XDebugClient running on Mercury

URL used was: http://titan/xdebug-tests/dbgtest.php?XDEBUG_SESSION_START=mysession.com

  1. Success
  2. Set up FileZilla FTP server on Titan, to support NetBeans ftp access to Titan.
    1. Perhaps another server would have been a better choice to support Internet-debugging, because there is no encrypted format compatible between Filezilla server and NetBeans

i.      Filezilla does FTP and FTP over SSL/TLS, but not SFTP

ii.      NetBeans does FTP and SFTP, but not FTP over SSL/TLS

  1. Set up a PHP project in NetBeans
    1. Set up a project for which the source files were already and only remote, in this case, so netbeans would pull my existing server php files to my dev laptop
    2. Set the source path to c:\websites\titan\www\xdebug-tests
    3. Set  up the connection to the ftp server  (note that Netbeans only does unencrypted ftp or sftp, doesn’t support ftp over ssl/tls, so doesn’t have an encypted solution for filezilla server which doesn’t do sftp)
    4. Set the destination directory to be /www/xdebug-tests
    5. Netbeans pulled my source file dbgtest.php to my local project directory on laptop
    6. I was able to debug that file, step through it, observe variable values, and finish (at which time the page appeared in a browser!), all without timing out!
    7. I created a bit more elaborate test file with a function call, that worked great, too:
    8. dbgtest2.php:

<?php

function foo($x,$y,$lbl){

$s=$x+$y;

echo $lbl.$s;

return true;

}

$a=1;

$b=2;

$c=$a+$b;

$r=foo($a,$b,”a+b=”);

if ($r) {

echo $r;

}

?>

Please follow and like us:
This entry was posted in Tech. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.