本文介绍了如何使用ddev进行xdebug/step-debugging?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在我的Drupal项目中使用ddev,现在想使用xdebug,所以我可以使用PhpStorm进行逐步调试(或者实际上任何IDE都可以).但是我似乎无法让它在断点处停止.我试图遵循ddev文档中的指令,但这没有实现.不能使我前进,但我不知道下一步该怎么做.我做到了:

I've been working with ddev on my Drupal projects, and now want to use xdebug so I have step-debugging with PhpStorm (or really any IDE would be fine). But I can't seem to get it to stop on breakpoints. I tried to follow the instructions in ddev docs but that doesn't do get me going, and I don't know what to do next. I did:

  • 按照此处讨论的那样设置172.28.99.99 IP地址
  • 使用config.yaml xdebug_enabled: trueddev start启用xdebug(并通过phpinfo进行检查以查看是否启用了xdebug.)
  • 将PHPStorm置于侦听调试连接"模式
  • Set the 172.28.99.99 IP address as discussed there
  • Enabled xdebug using config.yaml xdebug_enabled: true and ddev start (and checked with phpinfo to see that xdebug was enabled.)
  • Put PHPStorm in "listen for debug connections" mode

推荐答案

在任何设置中调试xdebug都可能会有些麻烦,但这是要采取的步骤:

Debugging xdebug in any setup can be a little trouble, but here are the steps to take:

  • 首先,重新阅读文档.
  • 确保您具有2019+版本的PHPStorm.直到2018.3及之前(包括?)的许多PHPStorm版本都与较新的XDebug版本不兼容.
  • 确保已启用xdebug;由于性能原因,默认情况下它是禁用的.大多数人在需要时使用ddev exec enable_xdebug启用它,并在完成后使用ddev exec disable_xdebug启用它,但是也可以在.ddev/config.yaml中启用它.
  • 不要假设正在执行一些晦涩的代码,并在其中放置一个断点.首先在index.php中的第一个可执行行上放置一个断点.很多人都认为它应该停止,但是他们的代码没有被执行.
  • ddev ssh放入Web容器.您可以ping host.docker.internal(并获得回复)吗?如果不能,则可能是防火墙过于激进.
  • 在PHPStorm中,禁用监听连接"按钮,使其不会监听.或者直接退出PHPStorm.
  • ddev ssh:telnet host.docker.internal 9000可以连接吗?如果是这样,则说明您在端口9000上运行了其他内容,可能是php-fpm.使用lsof -i :9000 -sTCP:LISTEN找出并停止它,或者更改xdebug端口,并将PHPStorm配置为使用新端口..在您的telnet命令没有连接之前,请不要继续.
  • 现在单击PHPStorm上的监听"按钮以启动它监听连接.
  • ddev ssh,然后再次尝试.它应该连接.如果不是,则PHPStorm可能没有监听,或者没有配置为在端口9000上监听? (请注意,先前的说明使用了其他端口,如果在v0.18.0之前使用XDebug,则可能会将PHPStorm设置为其他端口.)
  • 检查并确保已启用xdebug.您可以在容器内使用php -i,也可以使用希望提供phpinfo()输出的任何其他技术,包括Drupal的admin/reports/status/php.您应该看到This program makes use of the Zend Scripting Language Engine...with Xdebug v2.6.0xdebug.remote_enable: On.
  • 在项目的index.php的第一相关行中设置一个断点,然后运行该站点.它应该到此为止.
  • https://vimeo.com/268685753 简要介绍了XDebug在实践中的使用. li>
  • First, reread the docs.
  • Make sure you have a 2019+ version of PHPStorm. Many PHPStorm versions up to and (including?) 2018.3 were incompatible with newer XDebug versions.
  • Make sure xdebug has been enabled; it's disabled by default for performance reasons. Most people use ddev exec enable_xdebug to enable it when they want it, and ddev exec disable_xdebug when they're done with it, but it can also be enabled in .ddev/config.yaml.
  • Don't assume that some obscure piece of code is being executed and put a breakpoint there. Start by putting a breakpoint at the first executable line in your index.php. Oh-so-many times people think it should be stopping, but their code is not being executed.
  • ddev ssh into the web container. Can you ping host.docker.internal (and get responses)? If you can't, you might have an over-aggressive firewall.
  • In PHPStorm, disable the "listen for connections" button so it won't listen. Or just exit PHPStorm.
  • ddev ssh: Can telnet host.docker.internal 9000 connect? If it does, you have something else running on port 9000, probably php-fpm. Use lsof -i :9000 -sTCP:LISTEN to find out what is there and stop it, or change the xdebug port and configure PHPStorm to use the new one . Don't continue until your telnet command does not connect.
  • Now click the listen button on PHPStorm to start it listening for connections.
  • ddev ssh and try the telnet host.docker.internal 9000 again. It should connect. If not, maybe PHPStorm is not listening, or not configured to listen on port 9000? (Note that previous instructions used a different port, if you used XDebug before v0.18.0, you might have PHPStorm set to a different port.)
  • Check to make sure that xdebug is enabled. You can use php -i inside the container, or use any other technique you want that gives the output of phpinfo(), including Drupal's admin/reports/status/php. You should see This program makes use of the Zend Scripting Language Engine...with Xdebug v2.6.0 and xdebug.remote_enable: On.
  • Set a breakpoint in the first relevant line of the index.php of your project and then run the site. It should stop there.
  • https://vimeo.com/268685753 gives a quick screencast overview of XDebug in practice.

@heddn的注释:如果要让xdebug仅针对fpm运行,例如phpenmod -s fpm xdebug,而不是运行enable_xdebug.

A note from @heddn: If you want to have xdebug running only for fpm, phpenmod -s fpm xdebug for example, instead of running enable_xdebug.

来自@mfrieling的注释:如果您使用 XDebug Helper 设置一个IDE密钥,该密钥必须与服务器上的密钥相同.由于 DDEV 1.10.0 ,因此创建了一个真实用户在Web和db容器中为您提供用户名和用户ID",默认情况下,这些用户名和ID也用作IDE密钥.服务器上使用的IDE密钥,发送的浏览器扩展程序/cookie和PHPStorm必须相同.您可以通过以下两行创建文件.ddev/php/xdebug.ini来更改DDEV中的IDE密钥(将PHPSTORM替换为您要使用的值:

A note from @mfrieling: If you use a browser extension like XDebug Helper which sets an IDE key, that must be the same as on the server. Since DDEV 1.10.0 "there's a real user created for you inside the web and db containers, with your username and userid" which is also used as IDE key by default. The used IDE key must be the same on the server, the browser extension/cookie sent and PHPStorm. You can change the IDE key in DDEV by creating a file .ddev/php/xdebug.ini with the following two lines (replace PHPSTORM with the value you want use:

[XDebug]
xdebug.idekey = PHPSTORM

欢迎您在这里跟进!

这篇关于如何使用ddev进行xdebug/step-debugging?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 14:04