Fairway Technologies
Practical Development

Although some of these instructions are specific to Debian Linux (and more specifically, for MindTouch 2009 Enterprise VM), hopefully these steps will get you up and running with PHP debugging (and not the kind where you litter your code with print statements, or take a var_dump() all over your code…).

No, this is for the kind of debugging where you can set breakpoints, watch variables, look at the stack trace, and modify your code on the fly!  Hooray for that!

So, here’s what you need to do:

  1. Log into your MindTouch 2009 Enterprise VM as root (yes, root can be dangerous, but I trust you)
  2. You will need some PHP development prerequisites, like the ability to use Make and Pecl.  First, we’ll grab all the essentials for building from source (the # is the command-line prompt):
    # apt-get install build-essential
  3. We also need the php5 development tools, which includes Pecl:
    # apt-get install php5-dev
  4. Next, we can use Pecl to install XDebug:
    # pecl install xdebug
  5. Now you should have XDebug installed, but not configured.  Let’s do that.  We need to add a few lines to ALL of our php.ini files to enable and configure remote debugging:
    # nano /etc/php5/cli/php.ini
  6. This will open php.ini in the terminal editor.  Add these lines to the file, with these caveats:
    1. The path to xdebug.so must exist!  Check that it’s there
    2. The value for xdebug.remote_host must be your host IP address (not the vm’s IP address!).  If you don’t have a static IP, you may have to update this and restart the web server each time you fire up the VM!
    3. Make sure the xdebug.remote_port port is open in both your host and the VM (it probably is by default)
    4. You should ignore any prompts to add "extension=xdebug.so" to php.ini — this will cause problems

    zend_extension="/usr/lib/php5/20060613+lfs/xdebug.so"

    xdebug.remote_enable=1

    xdebug.remote_handler=dbgp

    xdebug.remote_mode=req

    xdebug.remote_host=192.168.1.72

    xdebug.remote_port=9000

  7. Use Ctrl-O, Enter to write the file, then Ctrl-X to exit
  8. Repeat steps 5, 6 and 7 for /etc/php5/apache2/php.ini
  9. Restart Apache
    # /etc/init.d/apache2 restart
  10. Restart MindTouch
    # /etc/init.d/dekiwiki restart
  11. Check to see if XDebug is installed correctly.  Run the following command, which lists all PHP modules.  You should see XDebug twice; once under [PHP Modules], and once under [Zend Modules]
  12. Make sure you have your Samba share set up so you can access it from your host filesystem
  13. In NetBeans, create a new project from existing sources, and point it to \drive\var\www\dekiwiki">\drive\var\www\dekiwiki">\drive\var\www\dekiwiki">\\<VM_IP_Address>\drive\var\www\dekiwiki
  14. Specify index.php as the home page
  15. Set a breakpoint somewhere in \includes\Article.php
  16. By default, NetBeans will automatically stop on the first line of the home page (for stepping through).  If you want it to only stop if it hits a breakpoint, go to Tools/Options, then select the PHP tab, and uncheck “Stop at first line”:image
  17. Click the Debug icon in the toolbar and weep with joy at the beauty of real debugging!

 

Of course, you may encounter problems along the way… if you do, the following resources may be of help:

Happy Bug Fixing!

posted on Thursday, January 21, 2010 12:35 PM |
What others have said
No comments posted yet.
What do you have to say?
Title *
Name *
Email (never displayed)
Url
Comment *  
Please add 7 and 6 and type the answer here: