Can't install xdebug on Mac with Homebrew

ぃ、小莉子 提交于 2019-12-02 17:53:23
Germain Carré

Add this repository: https://github.com/josegonzalez/homebrew-php#readme

Then use brew install php54-xdebug for PHP 5.4

Or brew install php53-xdebug for PHP 5.3

Or brew install php55-xdebug for PHP 5.5

// Working as of 2019

As homebrew removed the extra php repository containing a version with xdebug already installed, you have to install it manually.

Summary:

  1. brew install for php
  2. update your path
  3. pecl install for xdebug

Full example:

# update homebrew
brew update

# install a version of php, e.g. 7.0
brew install php@7.0

# now they tell you how to link it, in my case
echo 'export PATH="/usr/local/opt/php@7.0/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.0/sbin:$PATH"' >> ~/.bash_profile

# reload the file with the updated path, so we can use pecl
source ~/.bash_profile

# check that the path is to the correct php executable,
# and pecl is available
which pecl
# returns: /usr/local/opt/php@7.0/bin/pecl

# install xdebug, see https://xdebug.org/docs/install#pecl
pecl install xdebug

# check that everything worked
php --version
# should show a xdebug version
# like:  with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

The pecl install xdebug step above ended with

Build process completed successfully
Installing '/usr/local/Cellar/php@7.0/7.0.30/pecl/20151012/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.6.0
Extension xdebug enabled in php.ini

So I didn't even need to enable the xdebug.so in php.ini.

Forget about homebrew for a moment. I have tried doing with it and it is not a that good idea stability-wise. Instead stick to the default installation guide:

Installing XDebug on Mac OSX

  1. Go to http://xdebug.org/wizard.php and paste your phpinfo() content there.
  2. Download xdebug-2.2.5.tgz (http://xdebug.org/files/xdebug-2.2.5.tgz)
  3. Unpack the downloaded file with:

    tar -xvzf xdebug-2.2.5.tgz

  4. Run:

    cd xdebug-2.2.5

  5. Run phpize (install it via homebrew if you don't have it already)

    phpize

  6. As part of its output it should show (If it does not, you are using the wrong phpize):

    Configuring for: ...
    Zend Module Api No: 20100525
    Zend Extension Api No: 220100525

  7. Run:

    ./configure

  8. Run:

    make

  9. Run:

    cp modules/xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20100525

  10. Edit /etc/php.ini and add the line:

    zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so

  11. Restart the web server by typing in the terminal:

    sudo apachectl restart

Updated: 09-10-2019

For PHP 5.6 & 7.0 (not anymore in brew core)

brew tap exolnet/homebrew-deprecated

Use brew bundled pecl (when php installed with brew)

PHP 5.6 example

brew install php@5.6
$(brew --prefix php@5.6)/bin/pecl install --force xdebug-2.5.5

PHP 7.0 example

brew install php@7.0
$(brew --prefix php@7.0)/bin/pecl install --force xdebug

PHP 7.1 example

brew install php@7.1
$(brew --prefix php@7.1)/bin/pecl install --force xdebug

PHP 7.2 example

brew install php@7.2
$(brew --prefix php@7.2)/bin/pecl install --force xdebug

PHP 7.3 example

brew install php@7.3
$(brew --prefix php@7.3)/bin/pecl install --force xdebug

or link with brew first

PHP 5.6 example

brew install php@5.6
brew link --force php@5.6
pecl install --force xdebug-2.5.5
brew unlink php@5.6

PHP 7.0 example

brew link --force php@7.0
pecl install --force xdebug
brew unlink php@7.0

PHP 7.1 example

brew link --force php@7.1
pecl install --force xdebug
brew unlink php@7.1

PHP 7.2 example

brew link --force php@7.2
pecl install --force xdebug
brew unlink php@7.2

PHP 7.3 example

brew link --force php@7.3
pecl install --force xdebug
brew unlink php@7.3

If php -v gives you an error stating xdebug.so could not be found (assuming the pecl install went well) then you could have "old" settings like php.ini Un-/reinstalling php with brew does not remove ini files. Upgrading php to the new format does not update ini files. Just reinstall php with brew after you removed the folder /usr/local/etc/php/5.6/ and xdebug should work.

The new brew php installation does not link. You could do that yourself if you would like to (brew link --force php@5.6) Als you could install brew-php-switcher to switch between versions.

brew install brew-php-switcher
brew-php-switcher 5.6 -s
php -v
brew-php-switcher 7.0 -s
php -v

Keep in mind if you loaded php as a service you have to restart the service.

brew services restart php@7.0

I'd found this page while googling how to install for php 7.1 on , and I've decided to leave here my solution:

brew install homebrew/php/php71-xdebug

Maybe it'll be helpful for someone else in future...

This is my solution! Try it! ;)

1 Install developer tools:

xcode-select --install

2 Instal Autoconf. This is a tool for producing shell scripts that automatically configure software

brew install autoconf

3 If you use PHP >5.6

sudo pecl install xdebug

Have fun ;)

It looks like the repo moved, but it is available here, complete with instructions on how to access it from Homebrew.

It helped me to solve zend version and xdebug Xdebug requires Zend Engine API version 320160303. The Zend Engine API version 320180731 which is installed, is newer.

https://xdebug.org/wizard.php

Catalina

Starting with Catalina (Mac OS 10.15) PHP seems to be pre-installed (check with php -v) It could be installed along xcode or another software (I'm not sure) But I just installed Catalina yesterday and haven't installed Homebrew yet, Also xdebug is available too. I just had to rename /etc/php.ini.default and add this line

zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so

If you get this error after adding the tap and installing:

$ brew install "josegonzalez/php/php55"
==> Installing php55 from josegonzalez/php
Error: Formulae found in multiple taps: 
 * homebrew/php/php53
 * josegonzalez/php/php53

Please use the fully-qualified name e.g. homebrew/php/php53 to refer the formula.

it is because josegonzalez/php has been moved to homebrew-php/php recently, so you will face the previous error.

The idea is pretty simple, remove the old deprecated repo josegonzalez/php

brew untap josegonzalez/php
brew tap --repair
brew update

See the source of this solution to fix any other related bugs.

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