使用 Netbeans 和 XDebug 进行远程 PHP 调试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9818202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:41:59  来源:igfitidea点击:

Remote PHP Debugging with Netbeans and XDebug

phpdebuggingnetbeansxdebugremote-debugging

提问by David

I'm trying to use XDebug in the following scenario

我正在尝试在以下场景中使用 XDebug

  • Physical Host on Windows 7, with Netbeans 7.1.1
  • Virtual guest on Ubuntu, with Apache server and PHP 5.3.10
  • the PHP code of my website is on a shared folder on Ubuntu, in /var/www/mysite
  • the PHP code is accessible from my Windows host, on \\guestIP\mysite, with R/W permissions
  • Website accessible from http://mysite.local.fr, from both host and guest
  • Windows 7 上的物理主机,带有 Netbeans 7.1.1
  • Ubuntu 上的虚拟访客,带有 Apache 服务器和 PHP 5.3.10
  • 我网站的 PHP 代码位于 Ubuntu 的共享文件夹中,位于 /var/www/mysite
  • PHP 代码可从我的 Windows 主机访问,在 \\guestIP\mysite 上,具有 R/W 权限
  • 从主机和来宾均可从http://mysite.local.fr访问的网站

I created a Netbeans project from my Windows Host, pointing to \\guestIP\mysite. In the project Run configuration, I have the following:

我从我的 Windows 主机创建了一个 Netbeans 项目,指向 \\guestIP\mysite。在项目运行配置中,我有以下内容:

  • 运行方式:本地网络服务器
  • 项目网址:http: //mysite.local.fr
  • 索引文件:index.php(项目中确实存在)

In the Advanced Run Configuration:

在高级运行配置中:

  • I checked "Ask every time" (I also tried using "Do not ask" and starting the browser with the session key myself)
  • I tried setting '/var/www/mysite' - \\GuestIP\mysite for the mapping (and tried using nothing as well)
  • I haven't touched the proxy settings
  • 我检查了“每次都询问”(我也尝试使用“不要询问”并自己使用会话密钥启动浏览器)
  • 我尝试为映射设置 '/var/www/mysite' - \\GuestIP\mysite (并尝试不使用任何内容)
  • 我没有动过代理设置

I have the following in the php.ini on my Ubuntu VM

我的 Ubuntu VM 上的 php.ini 中有以下内容

xdebug.remote_enable = on
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = /tmp
;xdebug.remote_host=localhost,<HostIP>, mysite.local.fr
xdebug.remote_connect_back=1
xdebug.remote_handler=dbgp
xdebug.idekey="netbeans-xdebug"
xdebug.remote_mode=req

None of this works, Netbeans does not stop at any breakpoint from Windows.

这些都不起作用,Netbeans 不会在 Windows 的任何断点处停止。

Debugging directly from my VM with Netbeans works fine.

使用 Netbeans 直接从我的 VM 调试工作正常。

Can someone tell me how to get my debugger to work remotely from Windows? Thanks

有人能告诉我如何让我的调试器从 Windows 远程工作吗?谢谢

回答by Ethan

Sorry, i can't comment anymore. @David @JamesB41: I've been looking for this too. My setup is a Windows 7 host with NetBeans 7.1, and an Ubuntu VM in VirtualBox. I have the NetBeans project set up as a remote project, uploading and downloading using SFTP.

对不起,我不能再评论了。@David @JamesB41:我也在找这个。我的设置是带有 NetBeans 7.1 的 Windows 7 主机和 VirtualBox 中的 Ubuntu VM。我将 NetBeans 项目设置为远程项目,使用 SFTP 上传和下载。

The following setup works for me, just use your host's IP as remote_host, and make sure the VM can see it.

以下设置对我有用,只需使用您主机的 IP 作为 remote_host,并确保 VM 可以看到它。

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=10.217.165.193
xdebug.remote_port=9000
xdebug.remote_log="/tmp/log/xdebug.log"

NetBeans will stop at the entry point breakpoint (if you have the option set in PHP->Debugging). But, it won't stop on NetBeans-created breakpoints, because its running off the VM's files. You can use xdebug_break() though, and it will show stack and variables.It will stop at NetBeans breakpoints and highlight if you map the folders correctly in project config > Run Config > Advanced. Awesome. I am complete.

NetBeans 将在入口点断点处停止(如果您在 PHP->Debugging 中设置了该选项)。 但是,它不会在 NetBeans 创建的断点处停止,因为它会运行 VM 的文件。不过,您可以使用 xdebug_break(),它会显示堆栈和变量。如果您在项目配置 > 运行配置 > 高级中正确映射文件夹,它将在 NetBeans 断点处停止并突出显示。惊人的。我完整了。

(The connect_backconfig didn't seem to help, possibly because $_SERVER['REMOTE_ADDR'] isn't populated.)

connect_back配置似乎没有帮助,可能是因为没有填充 $_SERVER['REMOTE_ADDR']。)

回答by Krishna Chaitanya

Go through the below document for remote debugging using NetBeans. Very helpful. http://stuporglue.org/setting-up-xdebug-with-netbeans-on-windows-with-a-remote-apache-server/

阅读以下文档以使用 NetBeans 进行远程调试。很有帮助。 http://stuporglue.org/setting-up-xdebug-with-netbeans-on-windows-with-a-remote-apache-server/

回答by John

In know this is old but a good reminder. Make sure if you are using nat in virtualbox that you set port forwarding on the xdebug port back to the local machine typically 9000 by default.

知道这是旧的,但一个很好的提醒。确保如果您在 virtualbox 中使用 nat,您将 xdebug 端口上的端口转发设置回本地机器,默认情况下通常为 9000。

回答by troelskn

Another option is to have the VM configured to speak to its own localhost:9000 (default for xdebug) and then ssh in from host to VM and establish a port tunnel for that port back to the host machine. Then your host machine debugger simply connects to localhost:9000 and everything should work exactly as if they were running on the same machine.

另一种选择是将 VM 配置为与它自己的 localhost:9000(xdebug 的默认值)对话,然后从主机到 VM ssh 并为该端口建立一个返回主机的端口隧道。然后您的主机调试器只需连接到 localhost:9000,一切都应该像在同一台机器上运行一样正常工作。

See: Multiple users XDebug and PHP Debugging

请参阅:多用户 XDebug 和 PHP 调试

回答by Dmytro Dzyubak

Debugging remotely with Linux + Apache + PHP + xdebug + NetBeans (SFTP)

使用 Linux + Apache + PHP + xdebug + NetBeans (SFTP) 远程调试

I've got the following setup and it works.

我有以下设置并且可以正常工作。

Host PC (client)

主机(客户端)

  • Linux Debian Jessie **
  • NetBeans version 8.0.2
  • NetBeans has a project created as "PHP Application from Remote Server", that has to be debugged
  • NetBeans connects to Remote Server using SFTP
  • IP (for example): 192.168.0.2
  • Linux Debian 杰西 **
  • NetBeans 版本 8.0.2
  • NetBeans 有一个创建为“来自远程服务器的 PHP 应用程序”的项目,必须对其进行调试
  • NetBeans 使用 SFTP 连接到远程服务器
  • IP(例如):192.168.0.2

** I am aware that the OP question mentions Windows, but regarding that the main setup to solve this should be made on the VM, I hope this helps somebody anyway.

** 我知道 OP 问题提到了 Windows,但是关于解决这个问题的主要设置应该在 VM 上进行,我希望这对任何人都有帮助。

Guest PC (server) / Virtual Machine

来宾 PC(服务器)/虚拟机

  • Linux Debian Jessie
  • Apache
  • PHP 5.6
  • xdebug 2.2.5
  • IP (for example): 192.168.0.1
  • Linux Debian 杰西
  • 阿帕奇
  • PHP 5.6
  • xdebug 2.2.5
  • IP(例如):192.168.0.1

The following steps should be made on the "Guest PC (server) / Virtual Machine"

应在“来宾PC(服务器)/虚拟机”上进行以下步骤

  1. install xdebug sudo apt-get install php5-xdebug
  2. edit /etc/php5/apache2/php.ini,
  1. 安装 xdebug sudo apt-get install php5-xdebug
  2. 编辑/etc/php5/apache2/php.ini

add these lines right before the [Date]AND change xdebug.remote_hostto reflect your "Host PC (client)" IP:

[Date]AND 更改之前添加这些行xdebug.remote_host以反映您的“主机 PC(客户端)”IP:

[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=192.168.0.2
xdebug.remote_port=9000
  1. restart apache sudo service apache2 restart
  1. 重启阿帕奇 sudo service apache2 restart

Reference

参考

How to configure XDebug - Remote Debuging http://wiki.netbeans.org/HowToConfigureXDebug#Remote_Debuging

如何配置 XDebug - 远程调试http://wiki.netbeans.org/HowToConfigureXDebug#Remote_Debuging

you need to have correctly configured property xdebug_remote.host on remote machine. The IP address of local machine has to be defined in this property. For example, you want to debug your source code on remote machine 192.168.0.1 using Netbeans installed on 192.168.0.2. You need to change xdebug.remote_host on 192.168.0.1 to xdebug.remote_host=192.168.0.2. If doesn't work verify you have port configured in xdebug.remote_port open on both machines.

您需要在远程机器上正确配置属性 xdebug_remote.host。必须在此属性中定义本地机器的 IP 地址。例如,您想使用安装在 192.168.0.2 上的 Netbeans 在远程机器 192.168.0.1 上调试源代码。您需要将 192.168.0.1 上的 xdebug.remote_host 更改为 xdebug.remote_host=192.168.0.2。如果不起作用,请验证您在 xdebug.remote_port 中配置的端口在两台机器上都打开。

回答by GiorgosK

If all seems to be correct but you still get "Waiting For Connection" from inside netbeans you should try in your php.ini settings

如果一切似乎都正确,但您仍然从 netbeans 内部获得“等待连接”,您应该尝试在您的 php.ini 设置中

xdebug.remote_connect_back=on

as it allows connection from ANY ip or look at a lot more info on the issue http://www.devside.net/wamp-server/netbeans-waiting-for-connection-netbeans-xdebug-issue

因为它允许从任何 ip 连接或查看有关该问题的更多信息http://www.devside.net/wamp-server/netbeans-waiting-for-connection-netbeans-xdebug-issue