Today I spent 3 hours trying to setup a new dev environment with debugging on my MacBook, consisting of Eclipse, PDT (PHP Development Tools), and MAMP. Not exactly fun.
The critical part of what I wanted to set up was Xdebug. There are quite a few web designers/developers out there, who simply write code, save, refresh their PHP in the browser, and do a quick visual check. That might work for pretty simple stuff, but it can be hard to find tricky bugs when the web app achieves some level of sophistication. So Xdebug (or any other debugging tools like Zend) is a must for me.
First, you have to set up Eclipse to handle PHP. There are quite a few options here. You can download the many different IDEs based on Eclipse, download Eclipse with PDT, or install PDT as a plugin to an existing Eclipse installation. Since I already Eclipse installed, I decided to install it as a plugin.
In Eclipse, go to Help -> Install New Software.
Select the drop down menu for Work with:
Select Helios – http://download.eclipse.org/releases/helios.
Find the Programming Languages option, expand it, scroll down and select PHP Development Tools (PDT) SDK Feature.
Hit next, agree with the license, etc, etc.
Next, time to set up Xdebug in php.ini. If you installed MAMP in /Applications in Mac OS X, and assuming you want to use PHP 5.3, the php.ini is in /Applications/MAMP/conf/php5.3.
Find the [xdebug] section towards the end of the file, and update it to:
[code][xdebug]zend_extension=”/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”xdebug.profiler_output_dir = “/tmp/xdebug/”xdebug.profiler_enable = Onxdebug.remote_enable=Onxdebug.remote_host=”localhost”xdebug.remote_port=9000xdebug.remote_handler=”dbgp”xdebug.idekey=ECLIPSE_DBGP[/code]
Unfortunately, the Xdebug that comes with MAMP didn’t work for me, so I needed to get a more recent version. There are Windows binaries on xdebug.org, but no Mac OS X ones. Turns out Komodo, another IDE, has already compiled binaries of the new versions of Xdebug. Download the Xdebug binaries from Komodo and update the zend_extension path above or replace the xdebug.so.
We need to let Eclipse know it should be using MAMP PHP. Go into Preferences -> PHP -> PHP Executables. Edit the default. Change the executable path to the MAMP PHP, something similar to /Applications/MAMP/bin/php5.3/bin/php. Make sure PHP debugger is Xdebug.
Below PHP Executables is PHP Servers. Lets update this to work with MAMP. MAMP’s default Apache port number is 8888, we’ll set the URL to http://localhost:8888.
Let’s make sure that Xdebug is working with MAMP. Create a test PHP file to spit out phpinfo, which lists configuration settings:
Go to Run -> Run As -> PHP Web Page. Scroll down a bit in the browser and you should see a reference to Xdebug:
The Xdebug version that comes with MAMP is 2.0.x.