Today, I fired up my IDE (PhpStorm from JetBrains) to churn out a much needed and last minute bug fix in production. To my surprise, none of my breakpoints were halting the execution of my code! Talk about bad timing!I needed to deploy code not go on a troubleshooting safari! As with any “safari”, it’s of the utmost importance to know your environment. After all, it might not be the “Lion” that gets you, it could be some poisonous “bug” sneaking into your tent!
How to get Xdebug working again
First, assumptions about your environment:
- You already had Xdebug setup and working on Snow Leopard before you upgraded to Lion.
- You had been and are continuing to use MacPorts.
- I followed the MacPorts Migration guide to get to this point
- You don’t want to build from source.
If you don’t already have it, precompiled versions of Xdebug are available from ActiveState for most operating systems. The package can be downloaded at the company’s site. If you choose this option, take the xdebug.so from 5.3 directory and put it in:
On a Mac using MacPorts, your php.ini file is located in the /opt/local/etc/php folder. For others, php.ini may be located in your /etc folder.
If you don’t find your php.ini in the correct location, save a copy of php.ini.default from your PHP install as php.ini into the correct folder for your php environment.
Open up your php.ini file and make sure your existing Xdebug setup has the following:
xdebug.remote_enable = On
xdebug.remote_autostart = 1
If you don’t already have Xdebug setup in your php.ini, add the lines above to the end of file.
Even though I already had the xdebug.so file in the location indicated by the php.ini file setting (from my Snow Leopard install) I did not have the line “zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”
Maybe this line was there originally and at some point during my upgrade it was not preserved, I don’t know. What I do know is, once I added that and the line “xdebug.remote_autostart = 1”, Xdebug started working again.
Remember, after saving your changes, restart your apache server.
sudo apachectl restart
How did I get into this state?
Recently, I updated my MacBook Pro OS to 10.7 Lion and while some things went smoothly, some (especially with my PHP development environment) did not.
LION UPGRADE & MACPORTS: if your PHP/LAMP setup is based on using macports, after the upgrade the first thing you’ll notice with your LAMP stack is that nothing seems to work. If you find yourself in that position, read about how to resolve that here before fixing your Xdebug setup.
Apparently, after rebuilding my LAMP stack and dev environment, I had not yet needed to step through any of my code since the upgrade and that left me without a proper debugger.
In terms of efficiency, speed and performance, Moore’s law had been secretly replaced with Murphy’s law.
So, after verifying my php.ini and verifying my IDE’s preferences and settings for debugging PHP, I started searching the web for some solutions. Sure, my php.ini was preserved through the upgrade and the macports reinstall but my environment was definitely not the same.
Luckily, I’m not the only one who had this problem. But in case you’re having a hard time locating a solution, I thought it wise to blog and share the info that got me up and running.
About PHP and Xdebug
As a developer, I cannot imagine programming without a proper debugger. And for PHP, the Xdebug extension is the only way to go…well ok, maybe one of only a few ways to go. But, you know what I mean.
If you’re still using var_dump() die() as your debugging method, you can get familiar with Xdebug here.