// Working as of 2025

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 [email protected]

# now they tell you how to link it, in my case
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/[email protected]/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/[email protected]/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/[email protected]/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.

Troubleshooting

Need for some specific xdebug version

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)

Xcode not installed or ERROR: `phpize' failed.
xcrun --show-sdk-path || sudo code-select --install

(Thanks Louis Charette and Bernievv)

Error Warning: mkdir(): File exists in System.php on line 294 or ERROR: failed to mkdir /usr/local/Cellar/php/X.Y.Z/pecl/YYYYMMDD

The folder specified for extensions does not exists. Create it like the following:

mkdir -p "$(pecl config-get ext_dir)"

(Thanks Patrique Ouimet)

Answer from luckydonald on Stack Overflow
🌐
Xdebug
xdebug.org › docs › install
Xdebug: Documentation » Installation
You can install Xdebug through PECL on Linux and on macOS with Homebrew available.
Documentation
This site and all of its contents are Copyright © 2002-2026 by Derick Rethans. All rights reserved
Support
Where does this money go · † Invoices have a default 14 day payment term
Documentation » Step Debugging
If PHP/Xdebug run on a different machine than your IDE, or in a Docker container, then you need to tell Xdebug where to make the debugging connection to, as it is Xdebug that initiates the communication to the IDE, and not the other way around.
Documentation » All settings
Configures the IP address or hostname where Xdebug will attempt to connect to when initiating a debugging connection. This address should be the address of the machine where your IDE or debugging client is listening for incoming debugging connections.
Top answer
1 of 14
138

// Working as of 2025

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 [email protected]

# now they tell you how to link it, in my case
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/[email protected]/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/[email protected]/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/[email protected]/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.

Troubleshooting

Need for some specific xdebug version

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)

Xcode not installed or ERROR: `phpize' failed.
xcrun --show-sdk-path || sudo code-select --install

(Thanks Louis Charette and Bernievv)

Error Warning: mkdir(): File exists in System.php on line 294 or ERROR: failed to mkdir /usr/local/Cellar/php/X.Y.Z/pecl/YYYYMMDD

The folder specified for extensions does not exists. Create it like the following:

mkdir -p "$(pecl config-get ext_dir)"

(Thanks Patrique Ouimet)

2 of 14
78

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

Discussions

Laravel Herd is now out!
MacOS only, seem great but I'm gonna stick to Sail - not everyone is using the same hardware on my team More on reddit.com
🌐 r/laravel
75
27
July 21, 2023
Help to get PHP8 w/ xdebug in Docker on OSX running for local dev (phpunit) via PhpStorm in a checkout project
If I'm correct phpstorm can also run composer update on the remote interpreter thus will allow you to install php8 dependencies. Or try setting php 8 in your composer.json check out https://andy-carter.com/blog/composer-php-platform for example. Or run composer install --ignore-platform-reqs on your hist, this will ignore the php and extension constraints. More on reddit.com
🌐 r/PHPhelp
21
7
November 14, 2020
Install PHP 7.2 + xdebug on MacOS High Sierra (with homebrew as of July 2018)

Docker solved such a headaches.

More on reddit.com
🌐 r/PHP
21
0
July 24, 2018
Installing xDebug on Mac OSX with AMPPS
Probably quite a useful article for folks that aren't yet familiar with the disadvantages of running your development stack on OS X (unless your production stack is on OS X I guess...) - however I must stress it would be better for folks to use something like Vagrant / Docker to run a virtualised environment that matches your production environment. More on reddit.com
🌐 r/PHP
8
3
February 9, 2016
🌐
DEV Community
dev.to › scriptmint › installing-xdebug-3-on-macos-and-debug-in-vs-code-3l5h
Installing Xdebug 3 on MacOS and Debug in VS Code - DEV Community
November 28, 2022 - Earlier, whenever I used to install Xdebug, I had to look for multiple articles to make it work. Let me clarify, you don't need any Chrome Extension and also you don't need too much configurations. Its super simple. I use Homebrew to install various packages on my MacBook.
🌐
To The New
tothenew.com › home › how to install xdebug 3 on macos
How to install Xdebug 3 on MacOS | TO THE NEW Blog
August 30, 2023 - running: find "/private/tmp/pear/temp/pear-build-rootO1x6b4/install-xdebug-3.2.2" | xargs ls -dils 15982931 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 /private/tmp/pear/temp/pear-build-rootO1x6b4/install-xdebug-3.2.2 15983635 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 /private/tmp/pear/temp/pear-build-rootO1x6b4/install-xdebug-3.2.2/opt 15983636 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 /private/tmp/pear/temp/pear-build-rootO1x6b4/install-xdebug-3.2.2/opt/homebrew 15983637 0 drwxr-xr-x 3 root wheel 96 Aug 9 11:25 /private/tmp/pear/temp/pear-build-rootO1x6b4/install-xdebug-3.2.2/opt/homebrew/Cellar
🌐
YouTube
youtube.com › watch
Installing Xdebug on MacOS (M1 chip) - YouTube
Xdebug is awesome! Hopefully this video helps you install it :)
Published   September 27, 2023
🌐
Medium
olivierpicault.medium.com › installing-xdebug-on-mac-os-x-1f60df0a7317
Installing Xdebug on Mac OS X. Everything is explained here… | by Olivier Picault | Medium
November 25, 2020 - Installing Xdebug on Mac OS X Everything is explained here: https://xdebug.org/docs/install but this page is easier to follow. Looks like brew install php70-xdebug is not working anymore. So here is …
Find elsewhere
🌐
Davidperezgar
davidperezgar.com › en › blog › how-install-configure-xdebug-mac-debug-php-apps
How to install and configure Xdebug on Mac to debug your PHP applications
November 21, 2024 - Learn how to install Xdebug on your Mac step by step using Homebrew. Set up this powerful tool to debug your PHP code efficiently and optimize your workflow as a developer. 🚀
🌐
GitHub
gist.github.com › vicgonvt › aba1e7008c83af6ab20916e427d4a52f
Instructions for Installing Xdebug in a Mac with Laravel, Valet and Sublime Text · GitHub
December 8, 2016 - Instructions for Installing Xdebug in a Mac with Laravel, Valet and Sublime Text - Xdebug.md
🌐
Readybytes
readybytes.in › home › blog › how to setup xdebug in macbook
How to setup xdebug in Macbook | Ready Bytes
January 30, 2021 - I assume you already have installed PHP. Open the terminal in your mac (press cmd + space then type terminal and click it to open) ... The package is now ready to use but we need to do a few more configurations in the php.ini file but first ...
🌐
Profilingviewer
profilingviewer.com › installing-xdebug-on-high-sierra.html
How to install Xdebug on macOS Mojave (and High Sierra)
Download xdebug from Xdebug.org and extract the archive. ... Now, run phpize. ... Configuring for: PHP Api Version: 20170718 Zend Module Api No: 20170718 Zend Extension Api No: 320170718 · If so, you can skip the next part and continue with configuring and installing Xdebug.
🌐
GitHub
gist.github.com › ankurk91 › 22e4a07be552790a9d6a063ee1bace05
php xDebug v3 on Ubuntu/Mac and phpStorm · GitHub
macos 10.15 PEAR Version: 1.10.9 ... root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64 ... guest@192 CommandLineTools % sudo pecl install xdebug downloading xdebug-2.7.2.tgz ......
🌐
YouTube
youtube.com › watch
The Easiest Way to get Xdebug on a Fresh macOS Install - YouTube
Getting started with Xdebug can be daunting and frustrating. But it doesn't have to be!Let's take it step by step. First things first - lets get Xdebug insta...
Published   June 28, 2020
🌐
DevSense
blog.devsense.com › 2019 › how-to-install-xdebug-for-phptools-for-vscode-on-mac
How to install Xdebug for PHP Tools for Visual Studio Code on Mac OS - DEVSENSE Blog
In case of any missing x-code command line tools, run the following to install: $ xcode-select --install · To configure the system for Xdebug, you need to get the build ready.
🌐
Bbqsoftwares
bbqsoftwares.com › blog › xdebug-catalina
Installation of Xdebug on MacOS Catalina 10.15 | Louis Charette
The only real solution to use a custom version of xdebug would be to compile and use you own instance of PHP instead of the build in one. Long story short, Apple decided to nuke /usr/include in MacOS Catalina, which has been the default location for C header file for ever in UNIX systems. Trying to install through PEAR / PECL will return an error as the compiler will look for necessary headers file in /usr/include.
🌐
Medium
pezhvak.medium.com › installing-xdebug3-for-php8-for-mac-users-phpstorm-laravel-5622a18da3f8
Installing xdebug3 for PHP8 for mac users (PHPStorm + Laravel) | by Pezhvak IMV | Medium
February 14, 2022 - Since the release of xdebug3, few configurations that is related to xdebug.remote_enable.* and few more is renamed. you can read more of it here. Here i will go through all the details for installing xdebug and configuring it on PhpStorm to debug your Laravel (or any other PHP) application.
🌐
Rob Allen
akrabat.com › installing-xdebug-on-php-8-1-installed-with-homebrew
Installing Xdebug on PHP 8.1 installed with Homebrew – Rob Allen
I have recently set up a new M2 MacBook Air and as usual, installed Homebrew and then installed PHP. Homebrew is always up to date, so it installed PHP 8.1 for me. Again, as usual, I installed Xdebug using pecl install xdebug.
🌐
DevSense
blog.devsense.com › 2022 › install-xdebug-for-xampp-on-mac
How to install and configure Xdebug for XAMPP on Mac - DEVSENSE Blog
November 16, 2022 - Paste the following command in a macOS Terminal: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Once you have Homebrew installed, run the following command: ... These tools are part of GNU Build system and are necessary to be able to compile Xdebug.
🌐
Ryan Sechrest
blog.ryansechrest.com › 2022 › 10 › install-and-configure-xdebug-on-your-m1-mac-to-debug-php-applications-with-valet-and-phpstorm
Install and configure Xdebug on your M1 Mac to debug PHP applications with Valet and PhpStorm
October 18, 2023 - Xdebug allows you to set breakpoints in your PHP application. When you run that application, the execution will stop at each breakpoint you defined, providing you with an opportunity to inspect the state of your application, including things like which variables are defined, what value they contain, and a stack trace. We're going to install Xdebug, configure PHP and PhpStorm, and then set up a browser helper to set necessary cookies to begin debugging our code.
🌐
Devsense
docs.devsense.com › vscode › debug › xdebug-mac
Xdebug on Mac - PHP Tools for Visual Studio - Documentation
There are multiple ways how to install Xdebug on macOS: - Compile it from the source code. We have prepared a detailed step-by-step tutorial on how to do that. Please continue here - Use PECL and Homebrew.