andrewlocatelliwoodcock

Thoughts on Software

Debugging PHP: Setting up XDebug with XAMPP on Mac OSX

with 9 comments


Have been introduced to PHP recently when I was asked to take over a site developed for some friends by a third party. It is basically a customized WordPress site and the original developer had done a good job on it. I installed PHPStorm (I’m a big JetBrains fan), XAMPP (an easy to install Apache, PHP, mySQL setup) and then spent a number of very frustrating hours trying to get things working. Pretty permalinks was one issue I encountered (see my earlier post) and once that was resolved I needed to get debugging working. Now, I admit that I am very much a PHP noob but surely it shouldn’t be this fiddly to simply debug a website? ASP.Net / MVC just work out of the box for example …

XDebug is installed with XAMPP but I ended up downloading and installing the latest version (you can get the binaries prebuilt from ActiveState here) and then scratching my head. Eventually I figured out that XAMPP installs XDebug by default but does not configure it to be on by default. So if your debugging isn’t working even with PHPStorm’s “no configure” PHP debugging, try the following:

Open the PHP.ini file and if there is no [xdebug] section, add one by copying and pasting the following lines:

[xdebug]
zend_extension=”/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so”
xdebug.remote_enable=1
zend_extension tells PHP where to find the xdebug.so file, which on a Mac with XAMPP running PHP 5.3.1 will likely be in the given location. On Windows, the setting will be similar but point to xdebug.dll instead. The location will likely be something like: C:\php\modules\xdebug.dll for example.
xdebug.remote_enable sets whether XDebug debugging is enabled or not. This must be set to 1 to debug. Any other value and debugging will not work.
Lastly, set your breakpoints in PHPStorm, set it to listen for incoming connections and away you go.
There are a couple of very good blog posts here and here about setting up PHPStorm debugging and setting up XDebug for Mac. Overall, not so simples …

Written by andrewlocatelliwoodcock

January 3, 2012 at 19:58

Posted in Apache, PHP, XAMPP, XDebug

9 Responses

Subscribe to comments with RSS.

  1. I don’t ordinarily comment but I gotta state thank you for the post on this special one :D.

    Tayna Stawasz

    January 18, 2012 at 22:37

  2. Hey very nice blog!! Man .. Excellent .. Amazing .. I will bookmark your site and take the feeds also…I am happy to find numerous useful information here in the post, we need develop more techniques in this regard, thanks for sharing. . . . . .

    Mckinley Wickert

    January 26, 2012 at 17:27

  3. Hi, it does not work for me… I followed step by step the Tailored Instructions from xdebug.org website without any error or problem, but when restarting Apache, the phpinfo() simply cannot see the Xdebug extension. Any suggestion?

    Roberto

    January 27, 2012 at 17:20

    • Can you copy up here the exact XDebug section you have in your Apache config?

      andrewlocatelliwoodcock

      January 27, 2012 at 17:58

    • Also make sure that you have the right version of the .so / .dll file – I had a slightly mismatched version at one point (it was the latest one from XDebug) and had the same effect you are seeing now. I fixed it by reinstalling the version supplied with XAMP

      andrewlocatelliwoodcock

      January 30, 2012 at 21:50

  4. […] this post to set it up. Key […]

  5. The version that shipped with XAMPP did not work for me but the latest version from ActiveState worked great.

    David

    July 7, 2012 at 14:13

  6. I have a question if i may ask. I am trying to get xdebug working with phpstorm and MAMP Pro.
    My Phpinfo() says i am using TWO Php.ini files

    Configuration File (php.ini) Path /Applications/MAMP/bin/php/php5.4.4/conf
    Loaded Configuration File /Library/Application Support/appsolute/MAMP PRO/conf/php.ini

    Which one should i configure, or both, and do u think this could cause a problem…seems in the past i made the changes on both, u know if i go to the xdebug site and check..its says its not installed.

    thanks

    ken mcfadden (@eaglerockdude)

    October 11, 2012 at 14:31

  7. If you’re copying & pasting from this page watch out for the curly quotes (replace them with regular quotes)!

    Dave

    March 18, 2013 at 12:42


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: