Feed Subscribe
Exception has been thrown by the target of an invocation.


How to debug PHP applications on Windows

by ondrejsv 2. June 2010 00:20

If you need to dwelve into some PHP stuff and do not want to leave your comfortable Windows environment, just read on. It’s easy and no Apache will be harmed in this process.

Disclaimer: It’s been almost 10 years since I wrote the last serious line in PHP (PHP 3 then), so it’s possible that there is another way to debug PHP applications, or that I do not do things ideally or in the most elegant way but it did work for me.

You can install PHP conveniently and make it play nicely with IIS via the Microsoft Web Platform Installer. You then need some IDE to edit and debug the application. Microsoft Expression Web supports PHP but obviously not debugging. If you don’t mind spending some bucks, you can buy VS.Php or other similar product and use Visual Studio to do all PHP magic and stop reading. Or you may touch the other side of the world and download Eclipse with PHP Developer Tools (PDT) embedded. Unpack it but do not run yet. Download XDebug tool; note that you must download version that matches your PHP version and build flavor (if you don’t know, they have a fantastic tool that tells you what you want). Unpack it to any folder of your choice, open PHP.ini (by default in C:\Program Files\PHP) and at the very end of the file paste these lines:

[xdebug] xdebug.remote_enable=1 xdebug.remote_host="localhost" xdebug.remote_port=9000 xdebug.remote_handler="dbgp" zend_extension = C:\Program Files\php\plugins\php_xdebug-2.1.0RC1-5.2-vc6-nts.dll

Of course, the path in the last line should reflect the folder you unpacked XDebug zip into. Also note that if you have some non-standard build of PHP (on Windows it means something else than non-debug non-thread-safe), you may need to change the last line – read full instructions.

Verify that XDebug is correctly installed by running php.exe –m. The last line should read:

[Zend Modules] Xdebug

Restart IIS (iisreset) and now you may fire Eclipse. Go to Windows/Preferences/PHP/Debugger and change it from default Zend Debugger to XDebug.

Create a new file, type in some PHP code, set a breakpoint (Ctrl+Shit+B? What the…? I must find a way to change its key bindings to Visual Studio ones) and run. Yes, it works :-) :

image

Tags: