Installing Xdebug on PHP 8.1 installed with Homebrew
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.
This whirrs and clicks for a while downloading and compiling the xdebug.so and then fails with:
rob@ardent ~ $ pecl install xdebug downloading xdebug-3.1.5.tgz ... Starting to download xdebug-3.1.5.tgz (232,070 bytes) ... Build process completed successfully Installing '/opt/homebrew/Cellar/php/8.1.8/pecl/20210902/xdebug.so' PHP Warning: mkdir(): File exists in /opt/homebrew/Cellar/php/8.1.8/share/php/pear/System.php on line 294 ERROR: failed to mkdir /opt/homebrew/Cellar/php/8.1.8/pecl/20210902
Investigating, I found that /opt/homebrew/Cellar/php/8.1.8/pecl is a symlink to /opt/homebrew/lib/php/pecl, however, this directory doesn’t exist. So to fix, I created the directory and installed Xdebug again:
mkdir /opt/homebrew/lib/php/pecl pecl install xdebug
This time it worked:
rob@ardent ~ $ pecl install xdebug downloading xdebug-3.1.5.tgz ... Starting to download xdebug-3.1.5.tgz (232,070 bytes) ... Build process completed successfully Installing '/opt/homebrew/Cellar/php/8.1.8/pecl/20210902/xdebug.so' install ok: channel://pecl.php.net/xdebug-3.1.5 Extension xdebug enabled in php.ini
A quick test shows that all is now as it should be:
rob@ardent ~ $ php -v PHP 8.1.8 (cli) (built: Jul 8 2022 10:46:35) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.8, Copyright (c) Zend Technologies with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans with Zend OPcache v8.1.8, Copyright (c), by Zend Technologies
9 thoughts on “Installing Xdebug on PHP 8.1 installed with Homebrew”
Thank you! You saved me potentially hours in investigating.
Excellent instructions. Many thanks for sharing.
Is there the possibility that m2 cant work with php7.0 and xdebug 2.7.2?
I would be surprised if it did.
you saved me of grinding my teeth!! tks
Awesome, thanks! My symlinked directory was a little different, so I fixed it with:
sudo mkdir -p /usr/local/lib/php/pecl