简体   繁体   English

通过ssh隧道转发端口9000的xdebug远程调试 - 如何使其工作?

[英]xdebug remote debugging with port 9000 forwarded through ssh tunnel - how to make it work?

I have XAMPP 1.7.3a running on an "Amazon Linux" (Centos-derived) 32-bit instance in the Amazon EC2 cloud. 我在Amazon EC2云中的“Amazon Linux”(Centos派生的)32位实例上运行XAMPP 1.7.3a。 I downloaded/built/installed XDEBUG 2.1.0. 我下载/构建/安装了XDEBUG 2.1.0。 The relevant items in phpinfo() output look like this: phpinfo()输出中的相关项如下所示:

Directive                         Local Value  Master Value
xdebug.idekey                     ECLIPSE_DBGP ECLIPSE_DBGP
xdebug.default_enable             On           On
xdebug.remote_autostart           On           On
xdebug.remote_connect_back        Off          Off
xdebug.remote_cookie_expire_time  3600         3600
xdebug.remote_enable              On           On
xdebug.remote_handler             dbgp         dbgp
xdebug.remote_host                127.0.0.1    127.0.0.1
xdebug.remote_mode                req          req
xdebug.remote_port                9000         9000
xdebug.remote_log                 /opt/lampp/logs/xdebug_log
                                               /opt/lampp/logs/xdebug_log

I access the Linux box from a Windows laptop running XP SP3, using the SSH client in PuTTY version 0.60. 我使用PuTTY版本0.60中的SSH客户端从运行XP SP3的Windows笔记本电脑访问Linux机器。 Also on the laptop I've installed Eclipse PDT (Helios Service Release 1 Build id: 20100917-0705), and I think I've got it configured correctly to do XDEBUG remote debugging using port 9000. I say I think , because I've had difficulty figuring out how to do that, and how to use Eclipse PDT in general. 另外在笔记本电脑上我已经安装了Eclipse PDT(Helios Service Release 1 Build id:20100917-0705),我想我已经正确配置了使用端口9000进行XDEBUG远程调试。我说我 ,因为我'很难弄清楚如何做到这一点,以及如何使用Eclipse PDT。 But I did manage to get it configured and working for "remote" debugging of PHP code run by web pages served using XAMPP for Windows 1.7.3 on localhost (127.0.0.1), using port 9000. The phpinfo() output for the server on the laptop which PDT is able to debug is the same as above, except for: 但我确实设法配置并使用端口9000在localhost(127.0.0.1)上使用XAMPP for Windows 1.7.3提供的网页运行的PHP代码的“远程”调试工作。服务器的phpinfo()输出在笔记本电脑,其PDT 能够调试是与上述相同,除了:

xdebug.idekey       my_username     no value
xdebug.remote_host  localhost       localhost
xdebug.remote_log   no value        no value

I'm pretty sure these differences are not related to the problem. 我很确定这些差异与问题无关。 In fact, xdebug.idekey was originally "root novalue" on Linux, which I then changed to ECLIPSE_DBGP by both editing php.ini and setting environment variable DBGP_IDEKEY in the sudo-ed script that starts apache, in vain hope of getting things working. 事实上,xdebug.idekey最初是Linux上的“root novalue”,然后我通过编辑php.ini并在启动apache的sudo-ed脚本中设置环境变量DBGP_IDEKEY来更改为ECLIPSE_DBGP,徒劳地希望让事情正常工作。

I've got firewalls and a NAT router between the laptop and the Linux box. 笔记本电脑和Linux机箱之间有防火墙和NAT路由器。 So I am trying to use port forwarding through a PuTTY ssh tunnel to get the Linux XDEBUG talking to the Windows PDT. 所以我试图通过PuTTY ssh隧道使用端口转发来使Linux XDEBUG与Windows PDT通信。 I've been using X11 forwarding with PuTTY for a couple of months with no problems at all. 我一直在使用XT转发PuTTY几个月没有任何问题。 I set up the tunnel in PuTTY with local port 9000 forwarded to port 9000 on the Linux box, and port 9000 on the Linux box forwarded to port 9000 on 127.0.0.1, the PuTTY tunnel panel showing: 我在PuTTY中设置了隧道,本地端口9000转发到Linux机箱上的9000端口,Linux机箱上的端口9000转发到127.0.0.1上的端口9000,PuTTY隧道面板显示:

L9000  host...amazonaws.com:9000
R9000  127.0.0.1:9000

Looking at the PuTTY Event Log when the tunnel is set up, there appear to be no problems: 在设置隧道时查看PuTTY事件日志,似乎没有问题:

2010-11-16 18:07:59 Local port 9000 forwarding to host...amazonaws.com:9000
2010-11-16 18:07:59 Requesting remote port 9000 forward to 127.0.0.1:9000
2010-11-16 18:07:59 Remote port forwarding from 9000 enabled

But then when I go to PDT and click Debug on a configuration that specifies the remote web server, PDT shows background activity in the lower right corner that gets stuck at 57%, and if I click the icon to go to Progress view, that shows "Launching: waiting for XDebug session". 但是当我转到PDT并在指定远程Web服务器的配置上单击Debug时,PDT会在右下角显示背景活动,卡在57%,如果我单击图标转到进度视图,则显示“启动:等待XDebug会话”。

When this happens, the PuTTY Event Log shows: 发生这种情况时,PuTTY事件日志显示:

2010-11-16 19:05:42 Received remote port 9000 open request from 127.0.0.1:54474
2010-11-16 19:05:42 Attempting to forward remote port to 127.0.0.1:9000
2010-11-16 19:05:42 Forwarded port opened successfully
2010-11-16 19:05:42 Opening forwarded connection to host...amazonaws.com:9000
2010-11-16 19:05:42 Forwarded connection refused by server: Connect failed [Connection refused]
2010-11-16 19:05:42 Forwarded port closed

On the Linux box, /var/log/secure just shows: 在Linux框中,/ var / log / secure只显示:

Nov 16 19:01:51 ip-10-194-9-67 sshd[14555]: error: connect_to host...amazonaws.com port 9000: failed.

I've checked my /etc/ssh/sshd_config, and I think it's okay, even changing it explicitly to "AllowTcpForwarding yes", even though that is supposed to be the default. 我已经检查了我的/ etc / ssh / sshd_config,我认为它没关系,甚至将它显式更改为“AllowTcpForwarding yes”,即使这应该是默认值。 In my web searches for a solution, I did come across one linuxquestions posting where the final reply says something rather cryptic about sshd needing to resolve a hostname: 在我的网络搜索解决方案时,我确实遇到了一个linuxquestions帖子 ,其中最后的回复说明了一些相当神秘的sshd需要解析主机名:

this seemed to fix it: The hostname has always been domain-serv, since I always thought of my router as being domain.com...so after running hostname domain.com ...bam! 这似乎解决了它:主机名一直是域名服务,因为我一直认为我的路由器是domain.com ...所以运行hostname domain.com ... bam! It finally works... 它最终有效......

I guess sometimes it is too simple. 我猜有时它太简单了。 sshd had to be resolving domain.com to my router, ergo the connection failed. sshd必须将domain.com解析为我的路由器,因此连接失败。

I sounds like this might be related to my problem, but it makes no sense to me, and since it's pretty old, and the author didn't seem to understand it, either, I thought I would ask here rather than there... 我觉得这可能与我的问题有关,但这对我来说没有任何意义,因为它已经很老了,而且作者似乎也不理解它,我想我会问这里而不是那里......

I did notice that a similar question was asked in this forum almost a year ago that got just one 0-value response, presumably because the question was so lacking in detail as to be unanswerable. 我注意到大约一年前在这个论坛上提出了一个类似的问题 ,只得到了一个0值的反应,大概是因为这个问题缺乏细节而无法回答。 I hope this one has enough information, and isn't so long, so that somebody can steer me right. 我希望这个人有足够的信息,而且时间不长,所以有人可以指引我。 After reading the faqs and how to ask a question, it wasn't entirely obvious to me whether the correct use of the forum was to post something under that original poorly-asked but content-identical question, or to post this new one - I'm sure someone will let me know what was the right choice on that :-) 在阅读了常见问题解答以及如何提出问题之后,对我来说,正确使用论坛是否在原始的问题不完整但内容相同的问题上发布内容或发布这个新问题并不完全是显而易见的 - 我我相信有人会告诉我这是正确的选择:-)

I've been going nuts with this thing, and I suspect it's something pretty obvious to someone with experience. 我一直对这件事感到疯狂,我怀疑对于有经验的人来说这是非常明显的。 I'm a noob to most of this stuff (PHP, web programming, network admin, and this forum), though not to old-fashioned C programming and user-level Linux and Windows setup. 虽然不是老式的C编程和用户级Linux和Windows设置,但我对这些东西(PHP,网络编程,网络管理员和本论坛)都是一个菜鸟。

How embarrassing, apparently my port forwarding setup was something only a network noob would do? 多么尴尬,显然我的端口转发设置只是网络菜鸟会做的事情? I guess I had decided that since the Xdebug running on the web server needs to talk to the PDT debugger client on the laptop, and the PDT debugger client on the laptop also needs to talk to Xdebug on the server, and there's only one port number (9000), that therefore I needed to forward local port 9000 to remote port 9000, and also forward remote port 9000 to local port 9000; 我想我已经决定,因为在Web服务器上运行的Xdebug需要与笔记本电脑上的PDT调试器客户端通信,而笔记本电脑上的PDT调试器客户端也需要与服务器上的Xdebug通信,并且只有一个端口号(9000),因此我需要将本地端口9000转发到远程端口9000,并将远程端口9000转发到本地端口9000; I was confusing the direction of traffic with which side is the client initiating a (bi-directional) connection to a specific port that the server side is listening to. 我混淆了流量的方向,哪一方是客户端发起(双向)连接到服务器端正在侦听的特定端口。

What seemed to be happening was that the PDT debugger running on the laptop got stuck waiting for Xdebug running on Linux to make a connection. 似乎正在发生的事情是,在笔记本电脑上运行的PDT调试器等待在Linux上运行的Xdebug进行连接。 Since I couldn't really think of a situation where Xdebug would need to be listening to port 9000, waiting for the PDT debugger to initiate a connection (rather it would be waiting for the PDT debugger to send it a command over a connection that had already been established by its opening port 9000 when it saw the XDEBUG_SESSION parameter in the request), I decided just to get rid of the forwarding of local port 9000 to remote port 9000. I did that, and all of a sudden PDT was receiving the connection sent from the Linux server, and debugging proceeded normally from there. 因为我无法想到Xdebug需要监听端口9000的情况,等待PDT调试器启动连接(而不是等待PDT调试器通过具有连接的连接发送命令当它在请求中看到XDEBUG_SESSION参数时,已经通过它的开放端口9000建立了,我决定只是去掉本地端口9000到远程端口9000的转发。我这样做了,突然间PDT收到了从Linux服务器发送的连接,从那里正常进行调试。

But what's still not clear in my mind is why having the additional forwarding actually caused a problem. 但是在我看来还不清楚的是为什么额外的转发实际上导致了问题。 Couldn't it be possible for a pair of programs on different hosts to operate such that, depending on state, sometimes one was the listener and sometimes the other was? 难道不能让不同主机上的一对程序运行,这取决于状态,有时一个是听众,有时候另一个是? As long as the forwarding doesn't cause them both try to listen on the same port at the same time, I'd expect that to be okay. 只要转发不会导致它们同时尝试同时侦听同一个端口,我希望它没问题。

Bottom line is that things seem to be working now because of a simplification I made, but I'd like to understand why the unneeded complexity actually caused a problem. 最重要的是,由于我所做的简化,事情似乎正在起作用,但我想了解为什么不必要的复杂性实际上导致了问题。 I've read a lot of stuff, including the excellent explanation of ssh and tunneling in the O'Reilly book , but I still don't get it. 我已经阅读了很多东西,包括在O'Reilly书中对ssh和隧道的优秀解释,但我仍然没有得到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM