Search code examples
phpvisual-studio-codexamppxdebug

Xdebug MacOS Big Sur M1(ARM)


Honestly, I've tried everything trying to get this working. I am a bit new to MacOS but I am starting to get the hang of it.

I've installed Xdebug on my mac with XAMPP and VSCode as editor. It's still just not working and I think it is not connecting.

php.ini

[XDebug]
zend_extension = /Applications/XAMPP/xamppfiles/lib/php/extensions/xdebug.so
xdebug.remote_port = 9003
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/Applications/XAMPP/xamppfiles/temp"
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "localhost"
xdebug.remote_enable = On
xdebug.trace_output_dir = "/Applications/XAMPP/xamppfiles/temp"

VSCode launch.json:

      "type": "php",
      "request": "launch",
      "port": 9003

And yes, my file is at that exact location. If anyone has any glues on what's going on, I'll be glad to know.

UPDATE So I've check my error logs and I've gotten this problem:

[12-Oct-2021 07:00:06 UTC] PHP Warning: Failed loading Zend extension 'xdebug' (tried: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/xdebug (dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/xdebug, 9): image not found), /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so (dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so, 9): no suitable image found. Did find: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so: mach-o, but wrong architecture /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so: mach-o, but wrong architecture)) in Unknown on line 0

On the website it says that xdebug is only supported with homebrew. But installing php with homebrew is not the same thing as with XAMPP. I am starting to think that I just cannot use XAMPP and XDebug together but have to use the integrated apache.

XDebug Wizard:

Install the pre-requisites for compiling PHP extensions. On your Mac, we only support installations with 'homebrew', and brew install php && brew install autoconf should pull in the right packages."

When I look up the php version in the terminal it gets the version in homebrew, so I deleted it. It may be that when I used ./configure it took the PATH to homebrew. That is probably why the image is not correct.

Whatever the problem may be, I cannot find any kind of solution and have tried many things


Solution

  • After days trying to fix this I finally got it. What you need to do is the following:

    Step 1: Check PATH in Terminal

    which php
    

    Step 2: If this is not your current http server like XAMPP or MAMP please correct it by making a ./bash_profile MAMP Example: https://gist.github.com/irazasyed/5987693 XAMPP Example: https://gist.github.com/djandyr/c04950a1375e96814316

    Step 3: Check php version again (repeat step 1). If this is the version of your http server then it's OK.

    Step 4: Type in terminal

    php -v
    

    Step 5: If your xDebug cannot be loaded it will tell you why now. (or in the error logs). As I've said I've got a M1 Macbook and I think xDebug doesn't support M1.

    Step 6: To install xDebug terminal:

    arch -x86_64 sudo pecl install xdebug
    

    Step 7: Now restart all and try your phpinfo.

    Happy debugging!