Xdebug 在 Mac m1 上安装失败

问题描述 投票:0回答:4

我正在尝试在我的 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

错误显示:

我该如何解决这个问题?谢谢

php xdebug
4个回答
17
投票

这里发生的事情是您构建了扩展的

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.


3
投票

如果你遇到这个:

  • 文件
    which php
    结果显示
    Mach-O 64-bit executable arm64
    .
  • sudo pecl install xdebug
    仍然导致错误的架构 问题。

试试这个:

arch -arm64e sudo pecl install xdebug

注意:

arch -arm64
在我的案例中显示了坏的 cpu 类型错误。


1
投票

M1 上的解决方案

如果

pecl install xdebug
不起作用。使用
sudo
命令运行它。 不要尝试 arch x84 命令,因为它不再有效,因为 php 现在是在 arm cpu 架构中构建的。

解决方案:

sudo pecl install xdebug

0
投票

Macbook M1 2023 04/01 解决方案

  1. 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
    然后重新运行上面的命令
  1. 这将以路径成功结束。 记下它,你很快就会需要它:
Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so'
  1. php --ini
  2. 打开显示的ini文件:
    open /opt/homebrew/etc/php/8.2/php.ini
  3. 删除第一行(如果它说的是关于 xdebug 的话)
  4. 导航到 conf.d 目录(来自 php --ini)
    cd /opt/homebrew/etc/php/8.2/conf.d
  5. touch xdebug.ini
  6. open xdebug.ini
  7. 添加以下代码。 将扩展路径编辑为步骤 2 中的扩展路径
;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

© www.soinside.com 2019 - 2024. All rights reserved.