在远程服务器上的Docker内部进行Xdebug远程调试

问题描述 投票:1回答:1

我需要调试位于远程服务器上Docker容器内的PHP脚本。

通常,我在Windows中使用Visual Studio Code调试代码。我一直在用这种方式调试我的开发代码(位于Vagrant中),没有任何问题。

但是在远程服务器上的Docker中调试文件时,我无法正常工作。

这是我在php.ini上的xdebug设置(位于远程服务器上的docker中)

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host=172.18.0.1
xdebug.remote_port=9000
xdebug.remote_log=/tmp/debug.log

以上设置中的remote_host IP地址是从Docker内部看到的远程主机的IP。

我尝试了ssh隧道传输到我的远程服务器(从Windows,使用telnet)。

但是,当我尝试在浏览器上运行该站点时,我的Visual Studio代码无法检测到调试会话。

基本上我所做的是这些:

  1. 在我的本地计算机上启动调试会话(Windows)
  2. 使用ssh -R 9000:localhost:9000 [email protected]创建到远程服务器的ssh隧道(将服务器上的端口9000转发到本地主机:9000)>
  3. 将Docker上的端口9000映射到远程服务器上的端口9000
  4. docker中的Xdebug设置为侦听其主机(因此,从docker内部看到的主机IP地址,这是我从docker内部运行此命令得到的:/sbin/ip route|awk '/default/ { print $3 }'
  5. 当我运行站点时,/tmp/debug.log包含以下内容:

I: Connecting to configured address/port: 172.18.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///magento/test.php" language="PHP" xdebug:language_version="5.6.33-1+ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="12776" idekey="www-data"><engine version="2.5.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>

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

如何将Xdebug设置的连接从Docker'中继'到我的远程服务器,再到本地PC上的IDE?”>

我需要调试位于远程服务器上Docker容器内的PHP脚本。通常,我在Windows中使用Visual Studio Code调试代码。我一直在调试我的开发人员代码(位于...

php docker server xdebug ssh-tunnel
1个回答
0
投票

我没有成功通过ssh-tunnel:(

做同样的事情

但是ngrok有可能。您应该:

© www.soinside.com 2019 - 2024. All rights reserved.