63

I'm kind of new to using Homebrew, but I love it. It's so easy. I'm trying install Xdebug. Some of the posts on the web say to do this:

brew install xdebug

But it doesn't work. I get: Error, no available formula.

I did brew search xdebug and it returned:

josegonzalez/php/php53-xdebug    josegonzalez/php/php54-xdebug

I tried several different iterations of brew install with this including brew install php53-xdebug, but still no luck. Can someone help me? I can't find anything on Xdebug's site about using Homebrew, but yet posts on the web seem to indicate it's possible.

sehummel
  • 5,476
  • 24
  • 90
  • 137

14 Answers14

113

// Working as of 2023

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

Summary

  1. brew install php@<php version> for php
  2. update your path
  3. pecl install xdebug for xdebug

Full step-by-step 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.



If you need a special version of xdebug (e.g. your IDE doesn't like the 3.x.x versions), you can install a specific version xdebug-$VERSION, e.g. pecl install xdebug-2.9.8. You can find them on the list of available versions (Thanks Bower)

luckydonald
  • 5,976
  • 4
  • 38
  • 58
  • 2
    This install method using `pecl` worked - while Placeholder's method (from xdebug.org instructions) didn't. Thanks! – SUhrmann Jan 16 '19 at 21:54
  • 2
    You might have to run mkdir and create /usr/local/Cellar/php@7.0/7.0.30/pecl/20151012 folders. I created them and it worked xdebug.so installed successfully on the path. – Sarasranglt Mar 18 '20 at 10:47
  • 1
    `pecl install xdebug` was bringing in version 3.0.2 for me, as opposed to 2.6.0 as per your output, which didn't seem supported by my IDE. You can specify which version to install by appending `-version_number` to the command. e.g. `pecl install xdebug-2.9.8`. You can find the full list of xdebug versions available via pecl by looking [here](https://pecl.php.net/package/xdebug). – Bower Jan 19 '21 at 18:39
  • FWIW, Xdebug 2.x is no longer supported. – Derick Jul 22 '21 at 23:37
  • 3
    [mkdir()](https://patriqueouimet.ca/tip/installing-php-and-pecl-extensions-on-macos) might fail with the `Build process completed successfully Installing '/usr/local/Cellar/php@7.4/7.4.26_1/pecl/20190902/xdebug.so' Warning: mkdir(): File exists in System.php on line 294`. For me the dir `pecl` was a symlink to a non-existent dir. Remove this symlink with `rm` then install with `pecl` again. – Richard Tyler Miles Mar 14 '22 at 05:58
  • 1
    After mkdir() failed and using @RichardTylerMiles suggestion, I then had to edit the php.ini file and use the absolute path to `xdebug.so` which in my case was `/opt/homebrew/Cellar/php/8.1.6/pecl/20210902/xdebug.so` – Chad May 31 '22 at 17:46
  • mkdir() error occured for me, but running `sudo pecl install xdebug` after rm symlinks and creating the directory manually, it finally worked. – Shawn W Jul 15 '22 at 15:16
  • I received `mkdir()` error on MacOS M1 2020 what worked for me was described here: https://patriqueouimet.ca/tip/installing-php-and-pecl-extensions-on-macos `pecl config-get ext_dir | pbcopy` `mkdir -p {value from clipboard}` – Leo Fisher Jul 05 '23 at 18:09
77

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

Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
Germain Carré
  • 918
  • 7
  • 4
18

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

Placeholder
  • 4,651
  • 6
  • 33
  • 35
  • 9
    I know I'm digging up an old post but why would you tell him to disregard his package manager and possibly mess up his already in place config? He just simply needed to go into homebrew/php and choose his version when using brew install. This is not only bad advice but potentially dangerous. It's actually more troublesome and harder to update with your method. While it's good to know how to compile and make your own packages package managers were made for an explicit reason. – Brian Ellis Dec 30 '15 at 00:00
  • after make i'm getting a list of errors saying `In file included from ./php_xdebug.h:35: ./xdebug_code_coverage.h:47:36: error: a parameter list without types is only allowed in a function definition` – Yevgeniy Afanasyev Feb 21 '18 at 04:35
18

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
Mike
  • 1,883
  • 3
  • 23
  • 17
  • This is the easier way to install all necessary PHP modules. `brew install php@7.1 && $(brew --prefix php@7.1)/bin/pecl install --force xdebug` – Mike Nguyen Feb 21 '19 at 01:12
  • This answer seems to be the only one who actually shows how to install Xdebug for multiple PHP versions using only Homebrew and each's PHP Pecl installation. This is great! – Machado Jan 24 '21 at 00:18
6

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...

cn007b
  • 16,596
  • 7
  • 59
  • 74
  • 2
    The normal command `brew install php72-xdebug` didn't work for me. Using the full name worked. Thanks – Dewald Els Mar 22 '18 at 17:47
  • 2
    I really wish people would stop moving things around in homebrew...$ brew install homebrew/php/php71-xdebug Error: homebrew/php was deprecated. This tap is now empty as all its formulae were migrated. – BrDaHa Mar 08 '19 at 23:41
5

Xdebug on Big Sur for php8

php8 previously installed with brew.

~ % pecl install xdebug
ERROR: `phpize' failed

Ouch! Check xcrun. Thank you Louis Charette:

~ % xcrun --show-sdk-path
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

Error. Update Xcode. I just installed, and retest:

~ % xcode-select --install
xcode-select: note: install requested for command line developer tools

~ % xcrun --show-sdk-path 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

That's better! Now go back and try pecl again:

~ % pecl install xdebug
...
Build process completed successfully
Installing '/usr/local/Cellar/php/8.0.0_1/pecl/20200930/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.0.2
Extension xdebug enabled in php.ini

And check it worked:

~ % php -v
PHP 8.0.0 (cli) (built: Nov 30 2020 13:51:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
Bernievv
  • 71
  • 1
  • 3
  • 4
    im getting this error: Build process completed successfully Installing '/usr/local/Cellar/php/8.0.3/pecl/20200930/xdebug.so' Warning: mkdir(): File exists in System.php on line 294 PHP Warning: mkdir(): File exists in /usr/local/Cellar/php/8.0.3/share/php/pear/System.php on line 294 Warning: mkdir(): File exists in /usr/local/Cellar/php/8.0.3/share/php/pear/System.php on line 294 ERROR: failed to mkdir /usr/local/Cellar/php/8.0.3/pecl/20200930 – Cesar Mtz Apr 05 '21 at 21:42
  • Thanks @Bernievv, this really worked for me. `❯ php -v PHP 8.1.2 (cli) (built: Jan 21 2022 04:34:05) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies` – Steferson Jan 25 '22 at 21:22
  • @CesarMtz Navigate to /usr/local/Cellar/php/8.0.3 and remove the symlink with rm -f pecl, then run the `pecl install xdebug` command again. This creates the directory and fixes, per, https://github.com/Homebrew/homebrew-core/issues/41081#issuecomment-503256871 – Mike Dubs May 09 '22 at 20:42
3

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

grantDEV
  • 552
  • 1
  • 6
  • 10
1

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
azerafati
  • 18,215
  • 7
  • 67
  • 72
1

macOS 10.14 Mojave, Homebrew, PHP 7.3, April 2020

The description given in the following article was the only thing I could get to work on macOS 10.14 Mojave with Homebrew to install PHP 7.3 with working xdebug:

brew list | grep php | awk '{ print "brew uninstall --force "$1}' | bash        # Remove any old version of php.
rm -rf /usr/local/Cellar/php                                                    # To be sure, manually remove the php cellar folder.
brew untap homebrew/php                                                         # Then clean any php tap (extra repo).
brew cleanup                                                                    # Cleanup and Update your brew.
brew update
brew install php                                                                # Install the latest version of php.
pecl uninstall xdebug                                                           # Clean up old xdebug.
pecl install xdebug-beta                                                        # Install the latest version of xdebug-beta (The xdebug is not compatible with 7.3 so you need to use the xdebug-beta).
php -v                                                                          # Should now say "with Xdebug v2.9.4, Copyright (c) 2002-2020, by Derick Rethans"
Asbjørn Ulsberg
  • 8,721
  • 3
  • 45
  • 61
0

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

mipadi
  • 398,885
  • 90
  • 523
  • 479
0

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.

frazras
  • 5,928
  • 4
  • 30
  • 40
0

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

user838900
  • 109
  • 1
  • 2
0

As at May 2021, after installing PHP via Homebrew just run this:

pecl install xdebug

You'll need XCode installed as above answers have indicated.

The other answers involving other brew repositories or php74-* package namespaces are based on the old way Homebrew worked with PHP.

Scott
  • 37
  • 3
0

Improved Answer for MacOS

If you have followed the instructions written on the official docs and cannot see XDebug info using php -v command and instead getting errors, the last step you should do is the following:

  1. Go to the 99-xdebug.ini file you made in the described path and add this line:

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

(still errors? check your xdebug.so path if it is valid)

  1. After saving the changes, restart php using the command below:

brew services restart php@7.3 (change 7.3 with your php version)

  1. Then check if you can now see XDebug info using php -v command.

NOTE: "Described path" for 99-xdebug.ini is something like:

/usr/local/etc/php/7.3/conf.d (change 7.3 with your php version)

To be sure, type php --ini command.

Ahmet Firat Keler
  • 2,603
  • 2
  • 11
  • 22