Debug Drupal using Xdebug, Eclipse and Wamp

Hi All,

I was searching for debugging tool for drupal since i do module development and deals with so many websites during my projects. I found Xdebug is the one way to go . I am listing here step by step process to debug drupal using xdebug and Eclipse.

Step 1: Download Eclipse PDT from here http://www.eclipse.org/downloads/download.php?file=/technology/epp/downl...

Step2: Download php_xdebug-2.0.4-5.2.8.dll dll and place in C:\wamp\bin\php\php5.2.5\ext.

Step3: Edit your php.ini file with the following code at the end of file....
[xdebug]
zend_extension_ts="C:\wamp\bin\php\php5.2.5\ext\php_xdebug-2.0.4-5.2.8.dll"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"

Please check the path and version of php you are using in zend_extension_ts.

STEP 4: Restart your wamp.

STEP 5: On successful installation of xdebug you can see the below mentioned text just below php info.
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Xdebug v2.0.4, Copyright (c) 2002-2008, by Derick Rethans

The above mentioned text confirms successful installation of xdebug.

STEP 6: Open your Eclipse and add the drupal folder as php project. Todo this just create an emty php project and give the project workspace as c://wamp/www and add import your existing drupal folder to this project as a general folder import in eclipse.

STEP 7: Open Window->Preferences->General->Web Browser and set your browser here as external browser and select anyone of your browser.

STEP 8: Next go to Window->Preferences->PHP->Debug, and set the PHP Debugger option to XDebug

STEP 9: Now select your index.php --> right click -> Debug as -> Php webpage. Now your firefox open and you can see your project running.

STEP 10: Now goto window -> open perspective -> php debug. You can see now code is halted at first line of code.If you press play button in green color code will execute.

STEP 11: Set break points wherever you want in the files and click on step into to see the code flow.

STEP 12: To Debug other pages you can set the break points in corresponding module files and
open the corresponding page to debug.

STEP 13: To debug other that index.php copy the url like ?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=12581835388283 and insert after your url and keep break points in the relevant code.Happy debugging. :-)

TIP: To make module files open in eclipse please add extensions to *.module to window->preferences->general->editors->fileassociations file type as *.module and associated editor as PHP

Cheers,
Anil Sagar