使用 VirtualBox 进行远程 Xdebug [英] Remote Xdebug with VirtualBox

查看:67
本文介绍了使用 VirtualBox 进行远程 Xdebug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行远程调试.PHP 在 VM 上运行,我正在尝试从主机上的 NetBeans 进行调试.

I'm trying to get remote debugging to work. The PHP is running on a VM and I'm trying to debug from NetBeans on the host machine.

我已按照此处的说明,在 Windows 7 防火墙和 VirtualBox 网络设置中转发端口 9000,并设置NetBeans 中的路径映射.我的 xdebug 设置如下所示:

I've followed the instructions here, forwarded port 9000 in the Windows 7 firewall and in the VirtualBox network settings, and set up path mappings in NetBeans. My xdebug settings look like this:

xdebug.remote_enable = On
xdebug.remote_connect_back = On
xdebug.idekey = "netbeans-xdebug"
xdebug.remote_log = /tmp/xdebug.log

当我加载要调试的 URL 时(使用正确的 idekey),它会记录以下内容:

When I load the URL I want to debug (using the correct idekey) it logs the following:

I: Checking remote connect back address.
I: Remote address found, connecting to 192.168.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" 
         xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
         fileuri="file:///home/dev/web/projects/project.com.vm/httpdocs/index.php" 
         language="PHP" protocol_version="1.0" 
         appid="1380" 
         idekey="netbeans-xdebug">
   <engine version="2.2.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2012 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

但是,NetBeans 仍在等待连接.除了设置断点外,我已经将它设置为停在第一行.即使 NetBeans 未在侦听,日志文件也会包含已连接到客户端"消息.

However, NetBeans remains waiting for a connection. I've got it set up to stop at the first line, in addition to having a breakpoint set. The log file will include the "Connected to client" message even when NetBeans is not listening.

知道我可能遗漏了什么吗?

Any idea what I might be missing?

谢谢.

推荐答案

对我有用的是从我的主机运行以下内容:

What worked for me was running the following from my host:

ssh -R 9000:localhost:9000 yourUserName@yourVirtualMachine

注意使用 -R 标志而不是 -L.我在使用端口转发来使事情正常工作时遇到了麻烦,而 ssh 隧道运行良好.请注意,您也可以通过从 VM 内运行 ssh 命令并使用 -L 标志连接到主机来实现此目的.

Note the use of the -R flag instead of -L. I had trouble using port forwarding to get things working, while the ssh tunnel worked perfectly. Note you could also do this by running the ssh command from within the VM and connecting to the host with the -L flag.

由于我在使用 Vagrant 时遇到了这个问题,因此这是我个人使用的命令,请在出现提示时使用密码vagrant":

Since I ended up on this question while working with Vagrant, this is the command I personally used, use the password 'vagrant' when prompted:

ssh -p 2222 vagrant@127.0.0.1 -R 9000:localhost:9000

这篇关于使用 VirtualBox 进行远程 Xdebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆