远程服务器上Docker内的Xdebug远程调试

时间:2018-05-09 05:16:33

标签: php docker server xdebug ssh-tunnel

我需要调试位于远程服务器上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-tunneling到我的远程服务器(从Windows,使用telnet)。

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

基本上我所做的就是这些:

  1. 在我的本地计算机上启动调试会话(Windows)
  2. 使用ssh -R 9000:localhost:9000 username@myremoteserver.com
  3. 创建到远程服务器的ssh-tunnel(将服务器上的端口9000转发到localhost:9000)
  4. 将Docker上的端口9000映射到远程服务器上的端口9000
  5. docker中的Xdebug设置为侦听其主机(所以从docker内部看到的主机的IP地址,这是我从docker内部运行此命令得到的:/sbin/ip route|awk '/default/ { print $3 }'
  6. 当我运行网站时,/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>
    

    我怎样才能传递&#39; Xdebug从Docker,到我的远程服务器,到我本地电脑上的IDE的连接?

1 个答案:

答案 0 :(得分:1)

通过ssh-tunnel:(

但是ngrok是可能的。您应该:

  1. 在本地开发计算机上安装ngrok
  2. 运行ngrok tcp 9000;
  3. 根据xdebug.remote_port的信息设置xdebug.remote_hostngrok
相关问题