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