Friday, February 25, 2011

Integrating MAMP PHP and Eclipse PDT for CakePHP Debugging

There are a few steps necessary to get Eclipse PDT, MAMP, and a CakePHP app synchronized for debugging. Summarily, after adding the Zend Debugger to Eclipse, the php initialization file in MAMP must be modified so it can respond to Eclipse. MAMP is not pre-configured for use with Zend Debugger, so you must edit the php.ini file for MAMP. Find the location of this file in the phpinfo tab of MAMP (near the bottom in the screenshot):

Open this in a text editor such as vim, and you will find this info near the bottom (italicized configuration info added at this step):

[xdebug]
;zend_extension="/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

[Zend]
zend_extension="/Applications/MAMP/Library/modules/zend/ZendDebugger.so"
zend_debugger.allow_hosts=127.0.0.1
; zend_debugger.expose_remotely=always


Now that you have detailed the location of ZendDebugger.so, you need to actually add a copy of the file in that location. Go ahead and put a copy of ZendDebugger.co (which either you have already downloaded into your Eclipse plugin filesystem, or you can download it as part of the Zend Debugger package ) into this directory. Incidentally, ZendDebugger.co can be where ever you like, so long as the path in php.ini resolves to it.

Comment out any references to zend in php.ini, other than the ones in italics above. In addition, comment out xdebug references if they are not already commented out.

Finally, restart MAMP and look for this confirmation in your restarted phpinfo():


If debugging in Eclipse succeeds, the debugger will halt at the first instruction. Be sure to step through a few instructions (F5) to ensure it is working properly. Here is a thoughtful and concise external resource to follow as a further guideline.

Incidentally, CakePHP:


As stated above, this guide will help you get debugging to work with CakePHP. That part of the process entails a further step. Once you are in Eclipse debugging a CakePHP project, you may find the debugger prompts you to resolve the location of core php files as it steps through them. This will happen, for instance, when you debug CakePHP apps you have created by using the cake bake CLI prompt.

To resolve these prompts, simply make sure the following conditions are met:
  1. Your CakePHP app is in a project folder in Eclipse ( it has to be! )
  2. Your CakePHP core library is in a project folder in Eclipse. This way, the files are available to the IDE so Eclipse can step through them in a debug process.
This is a unique requirement of CakePHP. Since you are building from an external core library and debugging involves the core, it has to be in the IDE.