在Mac OS X上使用MAMP构建和安装Xdebug

9
我在使用MAMP的Mac OS X上构建和安装Xdebug时遇到了问题。
迄今为止,我在网上进行了广泛搜索,目前我卡在了Xdebug“安装向导”的部分,该部分告诉我在下载的源代码上运行“phpize”。
当我运行phpize时,我会收到以下消息:
new-host-2:xdebug-2.2.0 Dima$ 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:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

如果我执行which phpize,我会得到:

new-host-2:xdebug-2.2.0 Dima$ which phpize
/usr/bin/phpize

这不是我想要使用的版本。我想使用MAMP安装的版本phpize,因为我想在MAMP版本的PHP上安装Xdebug。这很困惑,因为我已经将MAMP特定的PHP bin路径添加到我的.bash_profile中并加入了$PATH变量。
如果我运行echo $PATH,我会得到:
new-host-2:xdebug-2.2.0 Dima$ echo $PATH

/opt/local/bin:/opt/local/sbin:/Applications/MAMP/bin/php/php5.4.3/bin:/Users/Dima/.rvm/gems/ruby-1.9.2-p290/bin:/Users/Dima/.rvm/gems/ruby-1.9.2-p290@global/bin:/Users/Dima/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/Dima/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

"MAMP特定的PHP路径显示在'/usr/bin'之前。接下来我尝试运行MAMP特定的phpize,手动提供整个路径,如下所示:"
new-host-2:xdebug-2.2.0 Dima$ /Applications/MAMP/bin/php/php5.4.3/bin/phpize
-bash: /Applications/MAMP/bin/php/php5.4.3/bin/phpize: Permission denied

现在我在Finder上检查了这些文件的权限,显示我对这个文件夹中的文件有完全的读写权限。我有点迷茫。

5个回答

15

我曾经也遇到同样的问题,但是我找到了一个更好的解决方案。

Xdebug已经在MAMP中了。

请检查你的php.ini文件:

/Applications/MAMP/conf/php5.x/php.ini

一直往下走,你就会看到

[xdebug]
;zend_extension="/Applications/MAMP/bin/php5.X/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

把那个改成

[xdebug]
zend_extension="/Applications/MAMP/bin/php5.X/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

重启服务器...完成

查看:想要运行Xdebug?MAMP是最简单的方法...


确实。XDEBUG已经可以与MAMP(至少是PRO版本)一起使用了。 - MEM
即使没有专业版,这个解决方案也可以工作!非常简单,感谢您的指导!:D - Daan
对于我的情况,它位于以下路径:/Applications/MAMP/bin/php/php7.X/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so - Suyash Dixit
1
您可以通过检查MAMP的启动页面,然后转到“工具-> phpinfo”,查看“已加载配置文件”的值来找到要加载的php.ini文件。 - lewsid
1
这些适用于xdebug2的指令不再适用于xdebug3。 - theking2

8

我尝试了Dmitry Samuylov's的解决方案,但对我并没有起作用。于是我继续搜索,找到了下面这个方法解决了问题。

  1. Download and unpack the MAMP Components from SourceForge

  2. Make a note of the path(s) that were not found during the phpize process. For me it was:

    /Applications/MAMP/bin/php/php5.2.17/include/php/main/php.h
    
    /Applications/MAMP/bin/php/php5.2.17/include/php/Zend/zend_modules.h
    
    /Applications/MAMP/bin/php/php5.2.17/include/php/Zend/zend_extensions.h
    
  3. Create the required path in your MAMP PHP directory. Again for me it was

    /include/php/
    
  4. Ensure the correct permissions on the directory

  5. Find the components for your target PHP version (in my case 5.2.17) and copy them into the path you created in step 3.

  6. Run the instructions for using the correct version of phpize from the Xdebug site


你有没有在哪里找到适用于你的目标PHP版本的组件的建议? - greg
1
要查找这些文件,请下载PHP源代码。例如,要使用5.4版本,请使用以下链接:http://us2.php.net/get/php-5.4.4.tar.gz/from/a/mirror。您可以提取并转储整个内容到步骤3中创建的/Applications/MAMP/bin/php/php5.2.17/include/php/目录中,或者只提取所需的文件。两种方法都可以! - greg
@greg不需要MAMP,它已经包含在内了。 - theking2

3

经过更多的研究和试错,我成功安装了它,并完成了以下步骤:

  1. 终端中,我运行了chmod u+x /Applications/MAMP/bin/php/php5.4.3/bin/*。以打开phpize和该路径中所有其他文件的执行权限。
  2. 按照这篇文章安装命令行工具。
  3. 按照这篇文章安装最新的Autoconf和相关工具。
  4. 之后,按照Xdebug向导提供的步骤进行操作,没有遇到任何问题。

1

MAMP / macOS 上的 Xdebug 3

需要指出的是,“解决方案”中的指令适用于 Xdebug 2,而我们现在已经使用的是 Xdebug 3。

要在 macOS 上的 MAMP 中启用 Xdebug 3,请按照以下步骤进行:

  • Open Tools → phpinfo

  • Locate the line Loaded Configuration File and copy the complete path (/Application/MAMP/......) of the php.ini file.

  • Open a Terminal and type the command open and paste the copied complete path of the active php.ini file.

  • Add the following lines

    [xdebug]
    zend_extension = xdebug
    xdebug.mode = debug
    xdebug.show_local_vars=1
    
  • Restart the MAMP web server.

检查

再次检查 phpinfo(刷新)并查找 ZEND 引擎下方的一行,以 Xdebug vX.X.X... 开头。在下面,您将找到一个带有大型 Xdebug 徽标的部分,显示版本和已启用或禁用的内容。

如果没有出现这个,请检查拼写错误或其他笔误。

请参阅Xdebug 文档,了解可以添加到您打开的 php.ini 文件的其他设置,例如 profile。如果更改 PHP 版本,则必须重复此过程。

替代方案

或者,购买 MAMP Pro 许可证,允许您从 MAMP 控制面板执行此操作。

附加步骤

为了启动调试器(或分析器),您需要在浏览器请求中添加一个 magic cookie。您可以使用浏览器插件(如 Chrome 的“Xdebug helper”)轻松添加这些内容。


0

这很容易。

在*C:\MAMP\conf\php x.x.x*目录中,打开每个相关的php.ini文件。

然后只需将以下行放入php.ini中:

[xdebug]

xdebug.default_enable=1

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1

zend_extension="C:\MAMP\bin\php\php5.5.0\ext\php_xdebug.dll"

嘿,Ramin,从你的回答来看,似乎你正在提供一个Windows的解决方案,但问题始终只涉及Mac OS X,甚至在问题标题中也是这样说明的。 - Dmitry Samuylov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接