Friday, September 16, 2011

Eclipse PHP XDebug

Error launching 'test'. The session could not be started. In order to generate debug information, please make sure that the debugger is properly configured as a php.ini directive.

I've been developing in PHP recently, and the code base is getting large enough that debugging by using print statements is getting unmanageable. I decided to try the Eclipse IDE for PHP.

I went to the Eclipse PDT page and downloaded the windows Eclipse IDE package for PHP which is supposed to contain everything you need.

Should be quick, right? This is what I did:
  1. Unzipped the zip file
  2. Start up Eclipse
  3. Created a PHP project, and imported some of my existing php files from the file system (in Navigator, right click on the project node > Import > General > File System etc).
Then came the part where I had to tinker with all kinds of settings. After a lot of tweaking, I wound up with this setup under Preferences > PHP:
  1. PHP Interpreter is "5.1/5.2" (I have 5.2.5 installed).
  2. PHP Executable fields are:
    1. Executable path: C:\Program Files\PHP\php.exe (THIS IS WRONG!)
    2. PHP ini file (optional): C:\Program Files\PHP\php.ini
    3. SAPI type: CLI
    4. PHP Debugger: XDebug
When I went to PHP > Debug I had some trouble. I'd originally tried the Zend Debugger, and wasn't able to get it to work. When I switched to XDebug, I couldn't get the PHP Debugger window to give me my configured PHP Executable as an option; the only option was "Not Defined". I had to restart Eclipse to get the correct option (my configured executable) to appear.

Then I right-clicked on a standalone test php file and tried to debug it as a script. No joy, I got a pop up dialog with the message "Error launching 'test'. The session could not be started. In order to generate debug information, please make sure that the debugger is properly configured as a php.ini directive."

I then spent about 2 hours trying to figure out how to get this to work, and nearly gave up.

I finally solved the problem by setting the "Executable path" above to C:\Program Files\PHP\php-win.exe. Yeesh. I don't know how you're supposed to figure this one out other than trial and error. Running php.exe -i from a DOS prompt works, although it does cause an error window to pop up. Running php-win.exe -i from a DOS prompt works without error.

Once that was changed, I was able to run and debug my script with breakpoints set!

Labels: ,