Select Page

Debugging PHP scripts in Eclipse

Debugging PHP scripts in Eclipse

Debugger are full-featured PHP debugger engine. They are interactive tools that allows
you to debug PHP scripts locally or remotely, from an IDE or from the console. There is 3
debugger on the market, XDEBUG (open source) , ZEND (closed source), DBG (commercial
but source code available) by luck all are free 🙂

I recommend you to develop with Eclipse PDT: The #Eclipse Foundation has released the 1.0
of the #Eclipse PHP Development Tools (PDT) project. #Eclipse PDT is a set of tools and
frameworks that enhance the productivity of developers using PHP, a popular, general-purpose
dynamic language that is especially suited for development of web applications and web services.

I have prepared a HowTo also for eclipse PDT, but it is still not ready for prime time.

DBG

 
  • Native debugger.
  • Debug locally or remotely
  • JIT. When enabled it can start debugging Just In Time when an error happens.
  • Supports back-trace, e.g. displays a list of all procedures with their local variables,
  • Step-in, step-out, step-over, run to cursor, change execution point withing current scope…), evaluate any valid php expression(s) or inspect arrays, classes and simple variables, modify their values on the fly and even create any new variables.
  • Supports conditional breakpoints and even global ones
  • Allows to change execution point
  • has embedded profiler,
  • Allows multiple debugger processes running simultaneously.
  • Has open COM interfaces for integration with win32-based 3rd party IDEs.
  • Linux, BSD, SunOs, MacOs and Win32 are supported.
  •  

    XDEBUG

     

    Xdebug provides:

    ZEND

    Debugger Extension can be downloaded from Zend Downloads

    Zend debugger in #Eclipse also works for MySQL statements!

    Installing ZEND debugger in #Eclipse

    The Zend Executable Debugger #Eclipse plugin adds PHP debugging capabilities to the #Eclipse environment.

    Add the following remote location to the eclipse manager, even if you have eclipse PDT

    http://downloads.zend.com/pdt

    zend.debugger.in.eclipse

    ZEND debugging mysql statement

    You’ll have to configured the PHP binary included with the ZEND debugger to be able to debug SQL queries. Search for a PHP.ini in your eclipse/plugins directory, you’ll find 2 files.

    Ex:

    • E:\eclipse\bin\PDT\plugins\org.zend.php.debug.debugger.win32.x86_5.2.12.v20071210\resources\php4\php.ini
    • E:\eclipse\bin\PDT\plugins\org.zend.php.debug.debugger.win32.x86_5.2.12.v20071210\resources\php5\php.ini

    And add these line in one of these files according to your PHP version

    extension_dir = "xampp_path/php/ext"
    extension="xampp_path/php/ext/php_mysql.dll"
    extension="xampp_path/php/ext/php_mysqli.dll"
    include_path =".;xampp_path/php;"

    Installing Zend debugger server in XAMPP

    Please note that the Zend Executable Debugger is not available from the #Eclipse PDT update Manager, so download ZEND debugger (Free) from Zend Downloads, you must extract the zip ZendDebugger-5.2.12-cygwin_nt-i386.zip.

    In the zip file, you’ll see multiple directories
    zend.debugger.install

    Use the version that match the one in XAMPP (you have note at chapter A, for me 5.2.3 so copy files from 5_2_x_comp) and copy the dll in
    xampp_path\php\extensions\

    zend.debugger.php.5.2.x

    Open the file php.ini located at xampp_path\apache\bin\php.ini
    and add these keys if they do not already exist:

    [XDebug]
    ;; Only Zend OR (!) XDebug
    ;zend_extension_ts="\xampp\php\ext\php_xdebug.dll"
    zend_extension_ts="\xampp\php\extensions\ZendDebugger.dll"
    zend_debugger.allow_hosts=127.0.0.1
    zend_debugger.expose_remotely=always

    ; this is to see output while debugging implicit_flush = On 

    Switch off all other debugger as it may conflict with Zen

    eaccelerator.enable="0"
    ;extension=dbg.dll
    :extension=xdebug.dll

    Restart apache, check for proper operations by going to http://localhost

    Note
    Apache will crash if you have more than one key in php.ini with the name zend_extension_ts, so uncomment all other entries!

     

    Debugging PHP in #Eclipse PDT

    Go to Debug dialog for creating and managing run configurations

    • Choose as Server Debugger: Zend Debugger
       debug.as.zend.eclipse
    • Choose as PHP Server: XAMPP
    • File should point to the root of your #Joomla! installation ex: /PROD2/index.php because in XAMPP htdocs directory I have a subdirectory /PROD2 with #Joomla! 1.5 inside
    • Remove the option Break at First Line
    • Keep URL to Auto Generate

    As seen in the screen shot below

    zend.debugging.eclipse.joomla 

    Now click on button configure

    • Give a Name, not important here, lets keep XAMPP
    • Enter the root URL that points to the document root of this server, for me it is http://localhost/PROD2

    zend.debugging.eclipse.joomla_1

    Go to tab "Path Mapping"

    • As Path on server enter E:\xampp\htdocs\PROD2
    • Choose Path in Workspace /PROD2

    zend.debugging.eclipse.joomla_2 

     

    Confirm all windows, and you can now start the debugger by clinking on debug button zend.debugging.eclipse.joomla_3

    You’re done, you can now set breakpoint and debug #Joomla! or your code easily

    zend.debugging.eclipse.joomla_4

     

     

     

     

    Installing #Joomla in #Eclipse

    We will now install #Joomla 1.0.15 and #Joomla 1.5.1 (newest version at time of writing into eclipse)
    Create two new PHP project in your workspace, one name joomla1.0.x the other joomla1.5.x for example

    Attention: the root workspace must be located at xampp_path/htdocs

     

    Setting Zend Debugger in #Eclipse PDT for #Joomla!

    In the PHP perspective of eclipse, go to the menu debug

    0 0 votes
    Article Rating
    Subscribe
    Notify of
    0 Comments
    Inline Feedbacks
    View all comments

    Categories

    0
    Would love your thoughts, please comment.x
    ()
    x