Xdebug 安装失败,因为 "phpize" 在带有 MAMP 的 macOS Big Sur 上失败

Xdebug installation failed because "phpize" failed on macOS Big Sur with MAMP

我正在尝试在我的 Mac 上安装 Xdebug,因为我正在使用 MAMP 进行本地开发。

我尝试使用 pecl 通过 运行 在终端中使用以下命令安装 Xdebug:

 sudo pecl install xdebug

但会发生以下情况:

hello-world:~ lois$ sudo pecl install xdebug
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-2.9.8.tgz ...
Starting to download xdebug-2.9.8.tgz (245,293 bytes)
...................................................done: 245,293 bytes
91 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
autom4te: need GNU m4 1.4 or later: /usr/bin/m4
ERROR: `phpize' failed

看起来 phpize 正在尝试定位一些不存在的文件,然后失败了。

xdebug 安装页面中没有提到那些文件,所以我不确定我做错了什么。

好的,所以我终于找到了解决问题的方法。

第一种解决方案:如果你使用的是MAMP

首先,我实际上是在使用MAMP进行本地开发。如果这也是您的情况,那么您 不需要 安装 Xdebug。

原因是 Xdebug 已经安装了 MAMP。

您只需要做两件事:

  1. 修改MAMP中的php.ini个文件:https://dillieodigital.wordpress.com/2015/03/10/quick-tip-enabling-xdebug-in-mamp-for-osx/
  2. 设置您的 IDE 以使用 Xdebug。我正在使用 VS Code,有很多关于如何使用 Xdebug 设置 VS Code 的教程。

第二种解决方案:您没有使用 MAMP,所以您绝对想在 Mac

上安装 Xdebug

如果您在使用 phpize 时遇到了同样的问题,那是因为较新版本的 macOS 具有不同的文件夹结构。

Xdebug 需要一个特定的结构,它不再存在。这种情况,看看这篇文章:https://bbqsoftwares.com/blog/xdebug-catalina

Autoconf 可能缺失

运行 brew install autoconf 再试一次

在 Apple M1 Silicon 上确保使用 arch -x86_64 sudo pecl install xdebug 安装 xdebug