php - Xdebug failed install on Mac m1

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.

Answer

Solution:

Solution for Macbook M1 as of 2023 04/01

  1. arch -arm64 pecl install xdebug
  • If ERROR: failed to mkdir /opt/homebrew/Cellar/php/8.2.4/pecl/20220829, run rm /opt/homebrew/Cellar/php/8.2.4/pecl then re-run above command
  1. This will end successfully with a path. Make note of it, you'll need it soon:
Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so'
  1. php --ini
  2. Open the ini file shown: open /opt/homebrew/etc/php/8.2/php.ini
  3. Remove the first line (if it says something about xdebug)
  4. Nav to conf.d directory (from php --ini) cd /opt/homebrew/etc/php/8.2/conf.d
  5. touch xdebug.ini
  6. open xdebug.ini
  7. Add the following code. Edit extension path to be the one from step 2
;XDebug
zend_extension="/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so"
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
;xdebug.mode=profile
xdebug.output_dir="/tmp"

Running php --version should show you a line about xdebug (like so with Xdebug v3.2.1)

Answer

Solution:

If you encounter this:

  • file which php result shows Mach-O 64-bit executable arm64.
  • sudo pecl install xdebug still resulted in the wrong architecture problem.

Try this:

arch -arm64e sudo pecl install xdebug

Note: arch -arm64 shown bad cpu type error in my case.

Answer

Solution:

Solution now on M1

if pecl install xdebug doesn't work. run it with sudo command. don't try the arch x84 command as it wont work anymore, since php is now build in arm cpu architecture.

Solution:

sudo pecl install xdebug

Source