I am required to use XAMPP for my university class, but I cannot get Xdebug to work with it.
I am using an M2 MacBook Air. I followed all the steps as listed by the Xdebug wizard, but no luck.
Both php.ini files in the XAMPP directory and opt/homebrew
directory have these lines added:
zend_extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
xdebug.mode=debug,develop
xdebug.client_port=9003
xdebug.client_host=172.17.0.1
xdebug.remote_handler=dbgp
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.idekey=VSCODE
xdebug.show_error_trace = 1
xdebug.max_nesting_level=250
xdebug.var_display_max_depth=10
xdebug.log=/var/log/xdebug.log
The xdebug.so
file is in that directory, I have checked.
When I enter php --version
into Terminal, it shows that Xdebug is installed:
PHP 8.2.10 (cli) (built: Aug 31 2023 18:52:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.10, Copyright (c) Zend Technologies
with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans
with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies
But, when I go to the XAMPP phpinfo.php
page and copy-paste my data into the Xdebug wizard, it keeps telling me that Xdebug is not installed. Please help me in this!
The Xdebug wizard output:
Xdebug installed: no
Server API: Apache 2.0 Handler
Windows: no
Zend Server: no
PHP Version: 8.2.4
Zend API nr: 420220829
PHP API nr: 20220829
Debug Build: no
Thread Safe Build: no
OPcache Loaded: no
Configuration File Path: /Applications/XAMPP/xamppfiles/etc
Configuration File: /Applications/XAMPP/xamppfiles/etc/php.ini
Extensions directory: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829
@YvesLeBorg can't really get rid of XAMPP because my uni professor requires us to use it... Anyways, thank you very much for the insight on the different PHP versions.
I uninstalled and deleted the PHP being detected by the CLI as to not confuse them, and then added these lines to my ~/.zshrc
file by using sudo nano ~/.zshrc
:
export XAMPP_HOME=/Applications/XAMPP
export PATH=${XAMPP_HOME}/bin:${PATH}
export PATH
...and then reloaded the login shell with:
$ exec $SHELL -l;
...which recognized the XAMPP PHP installation as the default. Huge thanks to this thread: Mac OSX PHP and XAMPP path issue
After that, when I used php -v
, it showed me this:
Failed loading /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so: dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so, 0x0009): tried: '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so' (no such file), '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
PHP 8.2.4 (cli) (built: Apr 6 2023 04:12:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.4, Copyright (c) Zend Technologies
...which shows that the PHP, and therefore the xdebug.so file from homebrew and XAMPP were compiled for different architectures. So, I downloaded the x86_64 build of xdebug using:
arch -x86_64 sudo pecl install xdebug
Finally, I set the path to the new xdebug.so in the php.ini as:
zend_extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
after which Xdebug is finally working! :)