我正在尝试在我的 Mac m1 上安装 Xdebug,我按照此页面(https://xdebug.org/docs/install)进行安装。这是我遵循的步骤:
step1 => 转到 cmd:arch -x86_64 sudo pecl install xdebug
step2 => 到 php.ini 删除这行代码
zend_extension="xdebug.so"
step3 => 到 php.ini 添加这个
[xdebug]
zend_extension=/opt/homebrew/lib/php/pecl/20190902/xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port="9003"
step4 => 进入命令:php -v
错误显示:
我该如何解决这个问题?谢谢
这里发生的事情是您构建了扩展的
x86_64
构建,但自制软件可能使用了 arm64e
架构。这些架构不兼容。
您可以通过以下方式验证您的 PHP 架构:
file `which php`
如果说
arm64e
,那么您需要文档中的原始命令:
sudo pecl install xdebug
如果是
x86_64
,那么你需要为Apple的双架构修改命令:
arch -x86_64 sudo pecl install xdebug
对于它的价值,文档说:在 Apple M1 硬件上,您 might 相反需要使用...,而不是 must.
如果你遇到这个:
which php
结果显示Mach-O 64-bit executable arm64
.sudo pecl install xdebug
仍然导致错误的架构
问题。试试这个:
arch -arm64e sudo pecl install xdebug
注意:
arch -arm64
在我的案例中显示了坏的 cpu 类型错误。
如果
pecl install xdebug
不起作用。使用sudo
命令运行它。
不要尝试 arch x84 命令,因为它不再有效,因为 php 现在是在 arm cpu 架构中构建的。
解决方案:
sudo pecl install xdebug
arch -arm64 pecl install xdebug
ERROR: failed to mkdir /opt/homebrew/Cellar/php/8.2.4/pecl/20220829
,运行rm /opt/homebrew/Cellar/php/8.2.4/pecl
然后重新运行上面的命令Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so'
php --ini
open /opt/homebrew/etc/php/8.2/php.ini
cd /opt/homebrew/etc/php/8.2/conf.d
touch xdebug.ini
open xdebug.ini
;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"
运行
php --version
应该会向您显示有关 xdebug 的一行(像这样 with Xdebug v3.2.1
)