I followed the instructions on xdebug.org to install Xdebug on my M2 Mac. For compiling the extension I installed PHP on my machine, so I installed the latest 8.2.
I also installed Xdebug with pecl with -arm64 (for my M2 as told by file which php) and and it loads when I try php -v. But on XAMPP I seem to have another PHP installation, which is 8.1, as it says in the phpinfo() on localhost.
The extension I created (obviously using the system 8.2 for compilation) with the 8.1 localhost-phpinfo on xdebug.org/wizard is in place.
When I check /Applications/XAMPP/xamppfiles/bin/php, it shows the reason why the extension is not loaded:
Failed loading /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so: dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so, 0x0009): tried: '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
There it says need "x86_64" although my mac is M2 and so arm64. Is it possible that I have a x86_64 PHP in XAMPP and arm64 php in my system PHP? How can I get a suitable xdebug-3.2.2.tgz? Or should I reinstall XAMPP with hopefully a arm64 PHP 8.2?
I am lost.
Yes, that is very likely. From what I understand, XAMPP is still
x86_64and native PHP isarm64.The source code is suitable for both. The binary that is created from the source code needs to be of either variant.
That should do the trick. Or even using their new 8.1.17 release. Their website says that "It supports intel (x64) or Apple M1 (arm64) CPUs". I can't verify that, as I don't have macOS.
Alternatively, you can use:
arch -x86_64 sudo pecl install -f xdebugto create an intel/x64xdebug.soand copy that to/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20210902/xdebug.sofor your XAMPP installarch -arm64 sudo pecl install -f xdebug. The latter overwrites the one that is created first. The-fflag is needed for PECL to allow that.