Netbeans + Xdebug + php不能正常工作

8

我的Netbeans无法使用Xdebug调试断点,我的配置看起来是正确的,所以我在第一次运行时配置了停止调试,但自那以后就再也没有工作过,有人遇到过这个问题吗?我的Netbeans版本是6.8,PHP版本是2.5.2。

我的php.ini文件:

zend_extension_ts = d:\wamp\bin\php\php5.2.5\ext\php_xdebug-2.0.2-5.2.5.dll
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=netbeans-xdebug
xdebug.profiler_enable=1
8个回答

10

在我的情况下,需要将这一行包括在 php.ini 中:

xdebug.remote_autostart=on
这是XDebug的配置部分:
[xdebug]
xdebug.remote_enable = on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey="netbeans-xdebug"
xdebug.remote_autostart=on
xdebug.profiler_enable = on
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "d:/wamp/tmp"

1
我使用Ubuntu,但是无法启动它。我按照从https://dev59.com/zG035IYBdhLWcg3wTuFu获取的信息,在安装xdebug后向/etc/php5/apache2/conf.d/xdebug.ini中添加了除最后两行之外的所有行,然后一切都运转得很好。 - Federico J.

4

xdebug检查清单:

  1. 检查在phpinfo()中是否加载了xdebug,并且运行时的值与预期配置相匹配
  2. xdebug.remote_enable应该on
  3. xdebug.extended_info应该on,以使断点起作用。
  4. xdebug.remote_port必须与IDE的端口相同且未使用
  5. xdebug.remote_handlerdbgp
  6. 如果xdebug.remote_autostart打开,则应将xdebug.idekey设置为与IDE的键相同
  7. 有时将xdebug.remote_host设置为内部网络IP或计算机名称而不是本地IP 127.0.0.1会有所帮助。PHP必须允许防火墙连接到此主机和端口。
  8. xdebug.remote_log设置为文件将有助于检查出错原因。调试工作正常后,请关闭日志记录。

示例配置:

[xdebug]
xdebug.extended_info=on
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=on
xdebug.idekey="netbeans-xdebug"

NetBeans 检查清单:

  1. 防火墙必须允许 NetBeans 监听与已配置主机的连接。
  2. 工具 -> 选项 -> PHP -> 调试,检查端口。如果 xdebug.remote_autostart 打开,请检查会话 ID。
  3. 项目类型必须为 PHP。
  4. 项目属性 -> 源,Web 根目录必须正确。
  5. 项目属性 -> 运行配置,索引文件需要是 php(或空白),才能使用 Ctrl+F5。
  6. 项目属性 -> 运行配置 -> 高级,调试 URL 应该是“默认”或“每次询问”。
  7. 项目属性 -> 运行配置 -> 高级,路径映射必须正确。(例如,如果没有映射,则为空)

(大多数默认选项都可以直接使用,所以如果你很绝望,可以尝试删除并重新创建项目。)

错误指令,在 PHP 5.5 和 xdebug 2.2 上测试过:

  1. PHP output_buffering 不需要关闭。(但可能有助于调试)
  2. 可以加载 OPCache(Zend Cache)模块。
  3. xdebug.profiler_enable 可以启用。

如果您发现了新的内容,请编辑此答案。


1

以下是我如何使其与多个PHP-FPM homebrew安装一起工作的方法。

我使用了这篇优秀的文章来进行多个安装:

https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew

在那篇文章的评论中,你会看到如何安装xdebug的建议,底线是:

brew install php56-xdebug

您需要为每个安装的PHP版本安装xdebug。Homebrew会为您安装的每个php版本创建一个xdebug.ini文件。每个文件都会有一个类似于以下路径的路径:

/usr/local/etc/php/<version # i.e. "5.6">/conf.d/ext-xdebug.ini

这篇文章安装了DNSMasq,它运行在xdebug的默认端口(9000),因此您需要将xdebug端口更改为其他端口(例如9001)。编辑上述提到的ext-xdebug.ini文件(如果安装了多个php版本,则可能有多个文件)。以下是我使用的设置:
[xdebug]
zend_extension="/usr/local/opt/php56-xdebug/xdebug.so"

; General config
; Dumps local variables on exception
xdebug.show_local_vars=On
; Dump server variables
xdebug.dump.SERVER=*
; Dump global variables
xdebug.dump_globals=On
xdebug.collect_params=4;

; Tracing
;xdebug.auto_trace=On
;xdebug.trace_output_dir= /opt/local/php_traces/
xdebug.show_mem_delta=On
xdebug.collect_return=On


; Debugging. You might need to specify your host with some additional options
xdebug.remote_enable=1
: from http://devzone.zend.com/1147/debugging-php-applications-with-xdebug/
xdebug.remote_host="localhost"
xdebug.remote_port=9001
xdebug.remote_handler="dbgp"

第一行和第二行是原始homebrew文件中的全部内容。
另外,当我安装了多个PHP版本时,这个ext-xdebug.ini文件只会为我安装的第一个PHP版本创建。我只需将此文件复制到其他PHP版本位置,并将第二行中的“php56-xdebug”部分更改为反映正确的php版本。
注意"xdebug.remote_port=9001"
然后在Netbeans中(我使用8.02 Mac osX10.10.3),我使用以下设置。 转到首选项-> PHP-> 调试
调试器端口:9001 停在第一行:(取消选中
监视和气球评估:(选中 - 有一个警告,但对我来说可以正常工作。)
值得注意的是,为了让xdebug在使用phpinfo()(或命令行php-i)时显示出来,我需要使用以下命令重新启动apache:
launchctl unload -Fw ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

sudo apachectl restart

launchctl load -Fw ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

由于某些原因,我的设置需要我每次启动时运行这个命令。有点麻烦,但我将其纳入一个 shell 命令中,以便轻松切换版本。
还有一个提示:brew info php56 的一部分如下所示:
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using
the brew version you need to make sure /usr/local/sbin is before /usr/sbin
in your PATH:

  PATH="/usr/local/sbin:$PATH"

在我的.profile_bash文件中添加这个之前,我对每个版本的php-fpm.conf文件所做的更改都没有被识别。其他所有东西似乎都正常工作,所以很令人困惑。

希望这能为其他人节省时间和麻烦。


1
(由于评论中的格式不正常,我将以回答的形式进行回复)
我也遇到了同样的问题:它曾经工作过,但后来就停止了。然而,在我的配置中,我已经找到了一个可以无障碍运行的点,并且我可以分享给你。
首先,我将ioncube加载器移到了php.ini的顶部:
[PHP]
zend_extension=/Applications/MAMP/bin/php5/zend/lib/ioncube_loader_dar_5.2.so

然后我将这些行放入xdebug配置中:

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

并将所有关于Zend Optimizer的行都注释掉

[Zend]
;zend_optimizer.optimization_level=15
;zend_extension_manager.optimizer=/Applications/MAMP/bin/php5/zend/lib/Optimizer-3.3.3
;zend_optimizer.version=3.3.3

我使用MAMP,这就是为什么我的库路径指向我的MAMP文件夹。

祝好运


1
  • 请确认您所使用的 Xdebug 版本与 PHP 版本相匹配(包括线程安全/非线程安全和 64 位/32 位)。
  • 在一些较新版本的 PHP 中,无论您是否使用 TS 版本的 Xdebug,都需要使用 zend_extension 而不是 zend_extension_ts。

我已经查看了这个,一切似乎都正确。 第一次使用时一切正常,但后来就停止工作了。 我不知道该怎么办... - Yargon
我本来想发表评论,但是内容太长了,而且评论格式也不正确,所以我另外写了一个“回答”。 - maggix

1

zend_extension = "C:\xampp\php\ext\php_xdebug-2.2.3-5.4-vc9.dll" xdebug.remote_enable = 1 xdebug.remote_handler = "dbgp" xdebug.remote_host = "localhost" xdebug.remote_port="9000" xdebug.remote_mode=req xdebug.trace_output_dir = "C:\xampp\tmp" xdebug.idekey="netbeans-xdebug"

这对我有效。


1

如果你还是卡住了,可以尝试以下方法:

  • 通过向导(http://www.xdebug.org/wizard.php)下载新版本的xdebug,按照说明操作,或许你会有好运。
  • 关闭防火墙可能会有帮助。
  • 在netbeans中使用不同的端口,例如,在我的情况下,使用9001在netbeans和9000在xdebug中工作。
  • php.ini文件中添加:xdebug.idekey=netbeans-xdebug
  • 查找是否有xdebug.ini文件,并将xdebug相关的php.ini行添加到该文件中。

始终确保重新启动您的apache服务以测试所有内容。


0
在我的情况下 - 主机在另一台服务器上,Net-beans 11 - 我需要打开终端到远程主机。
窗口 -> IDE 工具 -> 终端 -> 远程终端
附言:如果您在该终端中键入 export XDEBUG_CONFIG="idekey=netbeans-xdebug" 并启动调试会话,则可以调试控制台脚本。

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