Configure Xdebug for Magento
If you are going to be doing much of any type of development on Magento you are going to need a debugger pretty soon so that you can step through the code as it runs and find out what's really going on.
I'm currently using Eclipse IDE with the PHP Development Tools (PDT) and Xdebug running on a local Xampp server on 64 bit Windows 7. Documentation was pretty sparse when I set this up and there are a couple of gotchas so here are the steps to get it up and running.
I'll assume you've got your Magento local installation up and running already.
Eclipse and PDT
- You need a Java Runtime Environment installed to run Eclipse. I installed the JDK from here
- Download the latest Eclipse Classic from eclipse.org. Eclipse doesn't need installing just copy the folder somewhere and it's (almost) ready to run. Note: Don't put it in Program Files or Program Files (x86), I just run it from my home folder
- Modify the eclipse shortcut - Java is an unstable piece of shit and on Windows 7 your eclipse will fail to install the pdt unless you launch it with the following arguments -vmargs -Djava.util.Arrays.useLegacyMergeSort=true
- Launch eclipse
- Help - Install New Software
- Select Indigo - http://download.eclipse.org/releases/indigo in the Work with dropdown
- Expand Programming Languages and select PHP Development Tools
- Accept the license agreement and install
Conveniently Xdebug is already included in Xampp so it's just a case of uncommenting a few lines in the php\php.ini file in your xampp directory.
Search for the xdebug section and uncomment these
- zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
- xdebug.profiler_append = 0
- xdebug.profiler_enable = 0
- xdebug.profiler_enable_trigger = 0
- xdebug.profiler_output_dir = "C:\xampp\tmp"
- xdebug.profiler_output_name = "xdebug_profile.%R::%u"
- xdebug.remote_enable = 1
- xdebug.remote_handler = "dbgp"
- xdebug.remote_host = 127.0.0.1
- xdebug.remote_port = 9000
- xdebug.trace_output_dir = "C:\xampp\tmp"
Restart Apache and you're set.
Next you want to install the Xdebug helper to Firefox (tools - add-ons - get add-ons and search for xdebug helper). The allows you quickly toggle the xdebug output from your browser. Once it's installed and you've restarted Firefox you should see a little green bug in the bottom right-hand corner of the browser. If you can't see it turn on the add-on bar with ctrl+/
Set up your Magento project
Back to eclipse to set up your Magento project.
- File - New Project - PHP Project
- Name your project
- Choose Create project at existing location (from existing source) and browse to your Magento root folder (as used by xampp)
- Hit Finish and wait for the project to create
Set up xdebug as your debugger in eclipse
- Window - Preferences - PHP - Debug
- Change the PHP debugger to Xdebug
- Click configure
- Set Accept remote session (JIT) to "localhost" - OK
- Apply - OK
Quickly test the whole setup is working.
- Open your local Magento dev site in Firefox
- Open index.php in eclipse
- Add a breakpoint by double clicking to the left of the line number of the first proper line of PHP code (i.e. not all the commented stuff at the top - in the build I'm currently looking at it's line 27 beginning "if (version_compare") - you should see a blue circle in representing the breakpoint in the feint gray margin
- Switch back to Firefox and click the little green bug mentioned earlier (when it's running it has a little red "stop" icon on it - this is what you want to see)
- Refresh the page and eclipse should pop up asking you to confirm the perspective switch to the Debug perspective. Confirm and you will be taken to the debug with the code interrupted at the breakpoint you set earlier. You can now step through and inspect the code to your heart's content.
So now you've got it set up you want to start using it. A good place to start is with Erik Hansen of Classy Llama's walkthrough video