Magento xdebug with Netbeans

INTRODUCTION

Magento xdebug with Netbeans 7.3.1 and wampserver.

Taking the pain to have a debugger working is worth the effort. I will take you through setting up debugging with xDebugger on Netbeans and windows and wampserver in 14 steps. This how to debug with Magento using Netbeans and xdebugger tutorial is written for Windows, but in general it can be used for any operating system such as Linux or Mac OS.

  1. Install wampserver (latest preferable 32 bit). Wampserver already includes the xdebugger extension.
  2. Install Netbeans. Netbeans works well with local or remote debugging.
  3. Configure xdebug to work
  4. My php.ini xdebug configuration looks like


file: C:wampbinapacheApache2.4.4binphp.ini

; XDEBUG Extension
zend_extension = "c:/wamp/bin/php/php5.4.16/zend_ext/php_xdebug-2.2.3-5.4-vc9.dll"
[xdebug]
xdebug.default_enable=1
xdebug.remote_enable=on
xdebug.remote_handler="dbgp"
; for Magento running with IP is faster than looking up the hostsnames
xdebug.remote_host=127.0.0.1
; check if your firewall blocks this port or not
xdebug.remote_port=9000
xdebug.remote_autostart=on
; idekey must be present
xdebug.idekey="netbeans-xdebug"
xdebug.remote_mode=req
xdebug.remote_connect_back=1
;xdebug.remote_enable = on
;xdebug.profiler_enable = off
;xdebug.profiler_enable_trigger = off
;xdebug.profiler_output_name = cachegrind.out.%t.%p
;xdebug.profiler_output_dir = "c:/wamp/tmp"

 

  1. Restart your wamp server or apache, and check the phpinfo() whether the extension has been loaded with the correct settings. Below you will find a sample output on the screen of http://127.0.0.1/phpinfo.php

file: phpinfo.php (put it in your web documentroot) and run it

<?php phpinfo();
?>

 

After running phpinfo.php it will give this information. Check whether xdebug has been really loaded with the correct settings.

xdebug

xdebug supportenabled
Version2.2.3
IDE Keynetbeans-xdebug

 

Supported protocolsRevision
DBGp - Common DeBuGger Protocol$Revision: 1.145 $

 

DirectiveLocal ValueMaster Value
xdebug.auto_traceOffOff
xdebug.cli_color00
xdebug.collect_assignmentsOffOff
xdebug.collect_includesOnOn
xdebug.collect_params00
xdebug.collect_returnOffOff
xdebug.collect_varsOffOff
xdebug.coverage_enableOnOn
xdebug.default_enableOnOn
xdebug.dump.COOKIEno valueno value
xdebug.dump.ENVno valueno value
xdebug.dump.FILESno valueno value
xdebug.dump.GETno valueno value
xdebug.dump.POSTno valueno value
xdebug.dump.REQUESTno valueno value
xdebug.dump.SERVERno valueno value
xdebug.dump.SESSIONno valueno value
xdebug.dump_globalsOnOn
xdebug.dump_onceOnOn
xdebug.dump_undefinedOffOff
xdebug.extended_infoOnOn
xdebug.file_link_formatno valueno value
xdebug.idekeynetbeans-xdebugnetbeans-xdebug
xdebug.max_nesting_level100100
xdebug.overload_var_dumpOnOn
xdebug.profiler_aggregateOffOff
xdebug.profiler_appendOffOff
xdebug.profiler_enableOffOff
xdebug.profiler_enable_triggerOffOff
xdebug.profiler_output_dir
xdebug.profiler_output_namecachegrind.out.%pcachegrind.out.%p
xdebug.remote_autostartOnOn
xdebug.remote_connect_backOnOn
xdebug.remote_cookie_expire_time36003600
xdebug.remote_enableOnOn
xdebug.remote_handlerdbgpdbgp
xdebug.remote_host127.0.0.1127.0.0.1
xdebug.remote_logno valueno value
xdebug.remote_modereqreq
xdebug.remote_port90009000
xdebug.screamOffOff
xdebug.show_exception_traceOffOff
xdebug.show_local_varsOffOff
xdebug.show_mem_deltaOffOff
xdebug.trace_enable_triggerOffOff
xdebug.trace_format00
xdebug.trace_options00
xdebug.trace_output_dir
xdebug.trace_output_nametrace.%ctrace.%c
xdebug.var_display_max_children128128
xdebug.var_display_max_data512512
xdebug.var_display_max_depth33

 

  1. While debugging your local mysql (database server) will probably timeout. Adjust these settings in my.ini (default location: C:wampbinmysqlmysql5.6.12 ). This step is optional and not mandatory for xdebug to work.

file C:wampbinmysqlmysql5.6.12my.ini

wait_timeout=600

 

  1. Restart your wampserver or mysql server for these settings to take effect. Always also check php_error.log and mysql error log and apache error log from the wampserver control panel (windows icon). Solve the log errors if any were found.
  2. In Netbeans add a project.
  3. Netbeans > File > Project Properties (yourprojectname) > Project properties screen/popup will open > Select Run Configuration from left bar > Only fill in the project url > Set to "http://127.0.0.1/" (or your vhostname). See screen.
Set your project settings to work with xdebug and netbeans and Magento netbeans-and-xdebug-for-magento-project-dragonfroot-magento-extension-store-popup
  1. You are almost ready to test Magento with Netbeans and Xdebugger on Windows. Please adjust debugging settings in "Netbeans > Tools > Options > PHP > Debugging". Set the port to 9000 default, do not stop on first line, and make the ide.key="netbeans-xdebug" (also by default). Be sure to uncheck the irritating "Stop at first line". Then press OK.
Debugger settings netbeans and xdebugger for magento code on Windows Debugger settings Netbeans and xdebugger for magento code on Windows
  1. Before you start your debug session for Magento add a breakpoint (double click on the line number in any (php) file.
Magento debugging with IDE. Netbeans how to debug with Magento. Adding a breakpoint for Magento. Magento debugging with IDE. Netbeans how to debug with Magento. Adding a breakpoint for Magento.

 

  1. Press in Netbeans (Control+F5) or Netbeans > Debug > Debug Project (yourprojectname), that will start your debug session
  2. A browser window will open with url: "http://127.0.0.1/?XDEBUG_SESSION_START=netbeans-xdebug"
Browser opens white screen and stops, because debugger is stopping at breakpoint. Browser opens white screen and stops, because debugger is stopping at breakpoint.

 

  1. Your Netbeans will show at the Right Bottom, the status: "netbeans-xdebug" running

magento-and-netbeans-with-xdebugger-status-line-of-Netbeans-xdebugger-running

  1. And here comes the trick. In your Browser window, type any Magento shop url you would like to debug, but also add "?XDEBUG_SESSION_START=netbeans-xdebug" at the end of the url address.
  2. Make sure you login first normally by logging in via http://127.0.0.1/admin
    1. - For example. In your browser window change "http://127.0.0.1/?XDEBUG_SESSION_START=netbeans-xdebug" to (after logging in first) "hhttp://127.0.0.1/index.php/admin/permissions_role/editrole/rid/1?XDEBUG_SESSION_START=netbeans-xdebug"

     

  3. You can test any backend url this way, just make sure:
    1. - You are already logged in as a backend user (usually admin).
    2. - Start your debug session always with the default debug configuration. So always start the window: "http://127.0.0.1/?XDEBUG_SESSION_START=netbeans-xdebug" first.
    3. - Then in the same browser window change the url to the url of the backend Magento url you wish to debug with xdebugger. It MUST be the same browser window, where you change the address. For example change the address to: "http://127.0.0.1/index.php/admin/permissions_role/editrole/rid/1?XDEBUG_SESSION_START=netbeans-xdebug". Run that backend Magento url in your browser. If you have a breakpoint in for example "appcodecoreMageAdminhtmlBlockPermissionsTabRolesedit.php" the debugger will stop at that breakpoint.
    4. - Netbeans will take over the new debug session
    5. - Profit! Have a happy time using your IDE to debug Magento applications

     

The proof that it works:

 

Now debugging with an IDE is a piece of cake. Have fun. You have access to Call Stacks, watches, sessions, variables and are ready to defeat the monster Magento Now debugging with an IDE is a piece of cake. Have fun. You have access to Call Stacks, watches, sessions, variables and are ready to defeat the monster Magento

 

If you have any further questions, let me know. I'm happy to help you out configuring Netbeans to play nice with Magento and xdebug. Post a comment or send me an email.

REFERENCES
http://inchoo.net/ecommerce/magento/magento-xdebug/

http://roysimkes.net/blog/2009/11/debugging-magento-code-with-netbeans-6-8-beta/

https://netbeans.org/kb/docs/php/debugging.html

http://wiki.netbeans.org/HowToDebugPHPProjects

http://www.magentocommerce.com/boards/viewthread/33764/

http://www.magentocommerce.com/boards/viewthread/536338/

5 thoughts on “Magento xdebug with Netbeans”

Comments
My Cart
loading