Today I finally got round to getting debugging working with PDT (2.0) and Xdebug 2.
It wasn’t as hard as I thought as it turned out, I had previously presumed that because I make heavy use of mod_rewrite to rewrite my urls - Xdebug would not know how to find the correct class etc to debug.
The solution was simply to create a server mapping which tells the main site url e.g http://www.mysite.com to point to /ProjectName/index.php (which is where all URLs get pointed to).
Here are the exact steps I took:
- First of all, you need to obviously install Xdebug, which on ubuntu is as simple as doing an apt-get install php5-xdebug.
- Configure your php xdebug conf file located at (for ubuntu) /etc/php5/conf.d/xdebug.ini
- Add the lines:
xdebug.remote_enable=1
xdebug.remote_host=”localhost”
xdebug.remote_port=9000
xdebug.remote_handler=”dbgp”
xdebug.remote_log=”/tmp/xdebug.log” - Restart apache2… then check your phpinfo() shows the correct Xdebug settings you just added (and the same for the cli using php -i | grep -i xdebug).
- Now for the eclipse configuration… go to Window -> Preferences -> PHP -> Debug
- PHP Debugger - set to XDebug
- Server: Add a new server by clicking on the ‘PHP Servers’ link and point the URL of the document root to your Virtual Host as setup in Apache2 e.g. http://www.mysite.co.uk.
- IMPORTANT - if you use mod_rewrite - add a Path Mapping - Path on server should be your http://www.mysite.co.uk and path in workspace should be your main index.php (or whatever file you rewrite to).
- Set your PHP Executable to your php5 bin location (/usr/bin/php probably).
- You should now be golden. Go back to your project and use the Run -> Debug (F11) after selecting your index.php file in the project browser, and the debug perspective should open. Your script will be paused on the first line by default (you can change this in the debug prefs) so you can then step into your code and watch variables etc etc and other cool shit.
If you want to learn about mod_rewrite, then I suggest you RTFM :) Its a wonderful thang…