PHP Xdebug on OS X 10.9 Mavericks

The fast copy-paste way

sudo sh -c 'echo zend_extension=$(find /usr/lib/php/extensions -name "xdebug.so") >> $(php -qr "echo php_ini_loaded_file();") && apachectl restart'

This command do the following :

  • Finds the native Xdebug extension that comes with Xcode
  • Asks php which config file is loaded
  • Adds the Xdebug extension path in the config file
  • Restarts apache.

Compatible with Sierra, El Capitan & Yosemite with the bundeled apache, but untested with MAMP & XAMPP.

Before launching the command, make sure Xcode command line tools are installed : xcode-select --install


Don't know about using pecl. Getting Xdebug after an OS X install is pretty straightforward without pecl. You've got two easy options:

  1. Use the version already available at:

    /usr/lib/php/extensions/no-debug-non-zts-2010052/xdebug.so
    
  2. Build your own:

    1. Make sure you have the Xcode CLI tools: xcode-select --install will prompt you to install the CLI tools. With the CLI tools installed, there should be stuff inside /usr/include/php.

    2. Go to http://xdebug.org/download.php and download the source tarball for the version of Xdebug you want. For example: http://xdebug.org/files/xdebug-2.2.3.tgz.

    3. Extract the tarball and cd into the directory it created. Inside that directory you'll see a README. From here it's:

      $ phpize
      Configuring for:
      PHP Api Version:         20100412
      Zend Module Api No:      20100525
      Zend Extension Api No:   220100525
      $ ./configure --enable-xdebug
      checking for grep that handles long lines and -e... /usr/bin/grep
      checking for egrep... /usr/bin/grep -E
      checking for a sed that does not truncate output... /usr/bin/sed
      [... output ...]
      $ make
      [... output ...]
      

Your built xdebug.so is now at modules/xdebug.so. The phpize is critical to do with XCode CLI tools installed, because phpize sets up the build parameters for your version of PHP.

With your xdebug.so in hand from (1) or (2) above, you can add this block to the php.ini being used by your php or php-fpm:

[Xdebug]
zend_extension=<full_path_to_xdebug.so>
xdebug.remote_enable=1
xdebug.remote_host=<host running PHP (e.g. localhost)>
xdebug.remote_port=<port Xdebug tries to connect to on the host running PHP (default 9000)>