为什么 Xdebug 不能与 XAMPP 一起使用,即使它说它安装在终端中?

Why is Xdebug not working with XAMPP, even though it says it is installed in Terminal?

提问人:Anshu Shrestha 提问时间:9/27/2023 最后编辑:LazyOneAnshu Shrestha 更新时间:10/3/2023 访问量:103

问:

我需要在我的大学课程中使用 XAMPP,但我无法让 Xdebug 使用它。

我使用的是 M2 MacBook Air。我按照 Xdebug 向导列出的所有步骤进行操作,但没有运气。

XAMPP 目录和目录中的 php.ini 文件都添加了以下行:opt/homebrew

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

该文件在该目录中,我已经检查过。xdebug.so

当我进入终端时,它显示已安装 Xdebug:php --version

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

但是,当我转到 XAMPP 页面并将我的数据复制粘贴到 Xdebug 向导中时,它一直告诉我未安装 Xdebug。请帮帮我!phpinfo.php

Xdebug 向导输出:

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
php apache xampp xdebug

评论

0赞 shingo 9/27/2023
您需要确认您已经编辑了 phpinfo 中显示的 php.ini。
0赞 YvesLeBorg 9/27/2023
/var/log/不可写。尝试放置 xdebug.log 文件。完成后,重新启动 apache 和 php-fpm 进程。/usr/local/var/log
0赞 YvesLeBorg 9/27/2023
你对IP地址有绝对的把握吗?尝试 localhost no ?127.0.0.1.
2赞 YvesLeBorg 9/27/2023
最后,XAMPP 版本是 8.2.4 ...并且您正在 CLI 上使用另一个版本(可能是 brewed)进行测试。您是否尝试过使用 xampp 发行版中的那个运行。很有可能,他们没有在其中内置 xdebug 扩展。php --version
1赞 Álvaro González 9/27/2023
如果你将PHP作为Apache模块运行,你需要PHP解释器的线程安全版本,我猜,匹配的扩展。但是您正在尝试加载 Xdebug。如果你只需要 Xampp 设置,我会去掉另一个,它只会让你感到困惑。non-zts

答:

2赞 Anshu Shrestha 9/28/2023 #1

@YvesLeBorg无法真正摆脱 XAMPP,因为我的大学教授要求我们使用它...... 无论如何,非常感谢您对不同PHP版本的见解。

我卸载并删除了CLI检测到的PHP,以免混淆它们,然后使用以下方法将这些行添加到我的文件中:~/.zshrcsudo nano ~/.zshrc

export XAMPP_HOME=/Applications/XAMPP
export PATH=${XAMPP_HOME}/bin:${PATH}
export PATH

...然后重新加载登录 shell:

$ exec $SHELL -l;

...它将 XAMPP PHP 安装识别为默认安装。 非常感谢这个线程:Mac OSX PHP 和 XAMPP 路径问题

在那之后,当我使用 时,它向我展示了这个:php -v

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

...这表明 PHP 以及来自 homebrew 和 XAMPP 的 xdebug.so 文件是针对不同的架构编译的。因此,我使用以下命令下载了 xdebug 的x86_64版本:

arch -x86_64 sudo pecl install xdebug

最后,我在 php 中设置了新 xdebug.so 的路径.ini如下:

zend_extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so

之后 Xdebug 终于可以工作了!:)