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:
- Log into your MindTouch 2009 Enterprise VM as root (yes, root can be dangerous, but I trust you)
- 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
- We also need the php5 development tools, which includes Pecl:
# apt-get install php5-dev
- Next, we can use Pecl to install XDebug:
# pecl install xdebug
- 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
- This will open php.ini in the terminal editor. Add these lines to the file, with these caveats:
- The path to xdebug.so must exist! Check that it’s there
- 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!
- Make sure the xdebug.remote_port port is open in both your host and the VM (it probably is by default)
- 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
- Use Ctrl-O, Enter to write the file, then Ctrl-X to exit
- Repeat steps 5, 6 and 7 for /etc/php5/apache2/php.ini
- Restart Apache
# /etc/init.d/apache2 restart
- Restart MindTouch
# /etc/init.d/dekiwiki restart
- 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]
- Make sure you have your Samba share set up so you can access it from your host filesystem
- In NetBeans, create a new project from existing sources, and point it to drivevarwwwdekiwiki”>drivevarwwwdekiwiki”>drivevarwwwdekiwiki”>\<VM_IP_Address>drivevarwwwdekiwiki
- Specify index.php as the home page
- Set a breakpoint somewhere in includesArticle.php
- 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”:
- 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:
- Debugging PHP with NetBeans
- Configure XDebug on Linux
- More details about what you can do with debugging
- The XDebug Home Page
Happy Bug Fixing!