Search code examples
phpxdebug

Xdebug failed install on Mac m1


I'm trying to install Xdebug on my Mac m1, I followed this page(https://xdebug.org/docs/install) to install. This is the step I followed:

step1 => go to cmd: arch -x86_64 sudo pecl install xdebug

step2 => go to php.ini delete this line of code

zend_extension="xdebug.so"

step3 => go to php.ini add this

[xdebug]
zend_extension=/opt/homebrew/lib/php/pecl/20190902/xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port="9003"

step4 => go to cmd: php -v

The error shows:

enter image description here

How can I solve this problem? Thanks


Solution

  • What happened here is that you built a x86_64 build of the extension, but homebrew likely used the arm64e architecture. These architectures are not compatible.

    You can verify what your PHP's architecture is with:

    file `which php`
    

    If that says arm64e, then you need the original command from the documentation:

    sudo pecl install xdebug
    

    And if it's x86_64, then you need the command modified for Apple's dual architecture:

    arch -x86_64 sudo pecl install xdebug
    

    For what it's worth, the docs say: On Apple M1 hardware, you might instead need to use..., not must.