PHP Xdebug on OS X 10.9 Mavericks

痞子三分冷 提交于 2019-11-29 19:12:02

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)>
wal5hy

There are two issues here. The first is that you need to install Xcode command line tools with the command:

xcode-select --install

This will mean that the files previously not found in /usr/include/php/ will be available.

The next step is to install autoconf in the same way as Ares shows in his answer.

I would cd into your download folder first

cd ~/Downloads/
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-latest.tar.gz
cd autoconf-*
./configure --prefix=/usr/local
make
sudo make install

now you can run the pecl install command

sudo pecl install xdebug

If you are using Mac Yosemite 10.10 and none of the above answers solved the problem. Do the following:

  1. Open a terminal

  2. Execute find /usr/lib/php/extensions -name "xdebug.so" to know the path to the debug library.

  3. Execute sudo nano /etc/php.ini to open and edit the php.ini file
  4. In php.ini add the following lines at the end

    [XDebug]
    zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    

(When finished, type control+o to save and control+x to close the file)

(Don't forget to replace the value in zend_extension for whatever you got from the first terminal command)

  1. Execute sudo apachectl restart to load the new configuration
  2. Sit back and relax
greyfox

For anyone who is facing this issue I had to build autoconf from source. I followed this answer from another StackOverflow question.

https://stackoverflow.com/a/12333230/2272004

For the issue phpize error,try this will solve your problem: sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include

I had to brew install xdebug and choose for my version of PHP and it worked! For example,

brew install homebrew/php/php56-xdebug

For a PHP version 5.6 variant.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!