【问题标题】:xdebug in phpstorm and dockerphpstorm 和 docker 中的 xdebug
【发布时间】:2016-01-07 10:29:54
【问题描述】:

我设法将 xdebug 与 docker 和 phpstorm 结合使用。对于 http 调用...IE

http://192.168.99.100:8081/?XDEBUG_SESSION_START=PHPSTORM

但是当我尝试运行我的phpunit 测试时,它没有连接到 phpstorm

我在 phpstorm 中进行了正确的目录映射,还在我的 docker-instance export XDEBUG_CONFIG="idekey=PHPSTORM" 上运行了以下命令

我还在我的 docker 上进行了尝试:export PHP_IDE_CONFIG='serverName=web.docker' 并在 phpstorm web.docker 上命名了服务器配置。仍然在 http 但不是 CLI 上工作

那么我可以让 phpstorm 和 xdebug 在命令行中一起工作吗?

这是我的文件:/etc/php5/cli/conf.d/20-xdebug.ini

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
xdebug.remote_host=172.17.42.1
dxdebug.remote_autostart=1

当我打开日志并使用我得到的 xdebug_remote_host IP 地址时

W: Remote address not found, connecting to configured address/port: localhost:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:20:39

Log opened at 2015-10-13 12:22:58
I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: 172.17.42.1:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:22:58

Log opened at 2015-10-13 12:23:58
I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: 192.168.99.100:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:23:58

解决方案(编辑) 通过打开xdebug日志,我看到它成功连接到192.168.99.1所以这解决了问题

xdebug.remote_host=192.168.99.1

【问题讨论】:

  • 对于远程调试 IDE 使用服务器/主机名作为唯一 id 来决定使用哪些路径映射 (PHP | Servers)。对于 CLI 调试,未提供此类信息(无处可取),因此您需要手动提供(类似于您对 idekey 所做的)-serverName=ServerNameHere。还有——devnet.jetbrains.com/message/5534075#5534075
  • 我没有 100% 理解您的提示,但无论如何我在我的 docker 上进行了尝试:export PHP_IDE_CONFIG='serverName=web.docker'并在 phpstorm web.docker 上命名了服务器配置。仍然在 http 但不是 CLI 上工作
  • 1) 你可以阅读远程 CLI 调试/serverName 参数here 2) 你的PHP | Servers 是什么样子的(请截图) 3) 在调试 PHPUnit 之前 .. 尝试调试简单的脚本(放置它在你的项目根目录中;当然是本地和远程的)——至少你会保证它不能在整体上进行调试,而不是 phpunit 特定的时刻。 4) xdebug 日志中关于这次不成功尝试的内容(确保清楚/只有此请求详细信息)
  • 一些手册——可能有用:confluence.jetbrains.com/display/PhpStorm/…(不是 docker 特定的——只是一般的 CLI 调试)
  • 是的,我遵循了这个指南。我在根公用文件夹中尝试了一个非常简单的 echo 脚本......再次......在 HTTP 中运行良好,但在 CLI 中运行良好。这是我的 phpstorm 服务器设置屏幕prntscr.com/8pgsqt

标签: php docker phpstorm xdebug


【解决方案1】:

我现在想到两件事:

  1. xdebug.remote_host 设置是否正确?对于 HTTP 链接,您提供了一个 192.168. 地址,对于返回的方式,它是一个 172.17. 地址。你能在那个 IP 上 ping 你的主机吗?

  2. 在您的 ini 文件中显示:

    dxdebug.remote_autostart=1
    

    这只是一个错字,还是实际上在您的配置文件中?因为它应该读取前面没有“d”的xdebug。应该是:

    xdebug.remote_autostart=1
    

    您应该只在执行脚本时添加选项时添加 d,如下所示:

    php -dxdebug.remote_autostart=1 script.php
    

如果这还没有帮助,请通过在配置中添加类似这样的内容来启用远程日志:

xdebug.remote_log = /var/log/xdebug_remote.log

也许这将有助于找到问题。

【讨论】:

  • 1.是的,我可以ping 172.17.42.1
  • 感谢 Pampy,您关闭日志记录的提示显示它正在连接到以下 IP xdebug.remote_host=192.168.99.1,因此通过设置它,现在一切都很好。
【解决方案2】:

对我有用的是具有此配置的 ssh 隧道 xdebug.remote_connect_back=0 xdebug.remote_host=127.0.0.1

见:Xdebug with SSH tunnel on Docker for Mac

【讨论】:

  • 我不敢相信,但这就是我的问题。谢谢尤金
【解决方案3】:

从 Docker-17.06 开始,您可以通过静态主机名访问 Container 内 Mac 上托管的服务:docker.for.mac.localhost

完整答案在这里:https://stackoverflow.com/a/48495802/1241980

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-17
    • 2020-10-10
    • 2016-12-30
    • 1970-01-01
    • 2020-02-19
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    相关资源
    最近更新 更多