'Problem installing/rebuilding Xdebug under Apple Silicon M1

Failing to install XDebug under the new Apple Silicon M1 under Big Sur - After using pecl install xdebug and running php --ini I am getting the following error:

PHP Warning:  Failed loading Zend extension 'xdebug.so' (tried: /opt/homebrew/lib/php/pecl/20190902/xdebug.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/xdebug.so, 9): no suitable image found.  Did find:
        /opt/homebrew/lib/php/pecl/20190902/xdebug.so: mach-o, but wrong architecture
        /opt/homebrew/lib/php/pecl/20190902/xdebug.so: stat() failed with errno=22), /opt/homebrew/lib/php/pecl/20190902/xdebug.so.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/xdebug.so.so, 9): image not found)) in Unknown on line 0

Warning: Failed loading Zend extension 'xdebug.so' (tried: /opt/homebrew/lib/php/pecl/20190902/xdebug.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/xdebug.so, 9): no suitable image found.  Did find:
        /opt/homebrew/lib/php/pecl/20190902/xdebug.so: mach-o, but wrong architecture
        /opt/homebrew/lib/php/pecl/20190902/xdebug.so: stat() failed with errno=22), /opt/homebrew/lib/php/pecl/20190902/xdebug.so.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/xdebug.so.so, 9): image not found)) in Unknown on line 0

I tried recompiling xdebug from source (git clone git://github.com/xdebug/xdebug.git) with the same results. Can I force the correct architecture in the config.m4 when recompiling xdebug? - ANy other suggestions?



Solution 1:[1]

I needed to specify the architecture. It worked with :

arch -arm64 sudo pecl install xdebug

Solution 2:[2]

Simply open your php.ini file and replace this line:

zend_extension="xdebug.so"

with whatever the installation process offered you enter image description here

in my case it's: /opt/homebrew/Cellar/php/8.1.5/pecl/20210902/xdebug.so

And remember to restart your services!

Solution 3:[3]

tried install with pecl install xdebug and got this error:

Build process completed successfully
Installing '/opt/homebrew/Cellar/[email protected]/7.4.15_1/pecl/20190902/xdebug.so'

Warning: mkdir(): File exists in System.php on line 294

Warning: mkdir(): File exists in /opt/homebrew/Cellar/[email protected]/7.4.15_1/share/[email protected]/pear/System.php on line 294
ERROR: failed to mkdir /opt/homebrew/Cellar/[email protected]/7.4.15_1/pecl/20190902

I used fix from this link https://patriqueouimet.ca/tip/installing-php-and-pecl-extensions-on-macos and it helped

Your warnings are about architecture, maybe need to remove and install again - i was do all from arm64 terminal...

Solution 4:[4]

You will likely have to install Xdebug through PECL with:

arch -x86_64 sudo pecl install xdebug

Solution 5:[5]

Not sure if this was the problem. However, I did a full reset of my M1 Macbook. And this time I only used arm software (iterm, homebrew...), this time it installed without any issue.

Solution 6:[6]

On a fresh MacOS installation I was getting an error:

Warning: mkdir(): File exists in System.php on line 294 PHP Warning: mkdir(): File exists in /usr/local/Cellar/php/7.3.3/share/php/pear/System.php on line 294

Warning: mkdir(): File exists in /usr/local/Cellar/php/7.3.3/share/php/pear/System.php on line 294 ERROR: failed to mkdir /usr/local/Cellar/php/7.3.3/pecl/20180731

You simply need to make the directory the script cannot, to accomplish this, run the following:

pecl config-get ext_dir | pbcopy

mkdir -p {paste clipboard value}

Now you can install PECL extensions

pecl install xdebug

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fred
Solution 2 Mo Kawsara
Solution 3 Max
Solution 4 Derick
Solution 5 Guanhua Ding
Solution 6 Yamen Ashraf