vagrant - 在 Homestead 中执行 Symfony 控制台命令时 Xdebug 不工作

标签 vagrant phpstorm xdebug symfony4 homestead

执行bin/console cache:clear时,调试器不会在第一行代码处停止。

以下输出显示在 xdebug 日志中。

[18806] Log opened at 2019-02-04 15:58:42
[18806] I: Checking remote connect back address.
[18806] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[18806] I: Checking header 'REMOTE_ADDR'.
[18806] W: Remote address not found, connecting to configured address/port: 10.0.2.2:9000. :-|
[18806] I: Connected to client. :-)
[18806] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///home/vagrant/projects/valkplanner2/bin/console" language="PHP" xdebug:language_version="7.3.0RC3" protocol_version="1.0" appid="18806" idekey="PHPSTORM"><engine version="2.7.0beta1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2018 by Derick Rethans]]></copyright></init>
[18806]

我使用的是PhpStorm 2018.3.3。 以下是我在 PhpStorm 中的调试配置: enter image description here

这是 /etc/php/7.3/cli/php.ini 中的 Xdebug 配置。

[xdebug]
xdebug.remote_enable=1
xdebug.remote_log="/home/vagrant/xdebug.log"
xdebug.remote_handler=dbgp
xdebug.collect_params=1
xdebug.remote_connect_back=0
;use `route -n` to find dev machine IP address from homestead environment (seems to default to 10.0.2.2)
xdebug.remote_host="10.0.2.2"
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.show_local_vars=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir='/home/vagrant/profile'
xdebug.idekey=PHPSTORM

当我使用 URL 中的 ?XDEBUG_SESSION_START=PHPSTORM 或 Chrome 调试器插件向浏览器或 Postman 发出请求时,调试器工作得很好。

日志表明与 xdebug 的通信有效,但 PhpStorm 没有反应。

有谁知道问题出在哪里吗?

最佳答案

听起来像是另一个服务在 Xdebug 端口而不是 PhpStorm 上监听。

在 Mac 上,PhpStorm 无法检测 Xdebug 端口是否已被其他服务使用 ( https://youtrack.jetbrains.com/issue/WI-29443 )。

您可以使用 sudo lsof -nP -iTCP -sTCP:LISTEN 之类的命令来查看该服务可能是什么。最有可能的是 php-fpm (因为它默认使用 TCP 9000 端口)。在 Mac 和 Linux 上,php-fpm 很可能会安装在您的开发计算机上(通常与 PHP 一起安装)。

解决方案:将 Xdebug 端口从默认的 9000 更改为其他端口,最常见的是下一个端口 - 9001。在 php.ini 和 PhpStorm 中执行此操作(确保此时没有监听调试连接;如果监听,则停止并重新启动)。如果您正在使用某些网络服务器(例如 Apache),您可能还需要重新启动该服务器(以便 PHP 读取新配置)。

关于vagrant - 在 Homestead 中执行 Symfony 控制台命令时 Xdebug 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54520003/

相关文章:

PhpStorm 不会使用 2 个空格作为缩进

php - 安装Xdebug后phpinfo中的OLDPWD是什么?

php - 无法在 Nginx 上使用 Laravel 在 PhpStorm 中触发 Xdebug 中断

linux - puppet exec 返回 1 而不是 [0]

windows - 自从 Docker 工具箱在 Windows 上安装后,Vagrant 不起作用

vagrant - 如何完全卸载 VVV vagrant?

visual-studio-code - 如何在 Visual Code 中将文件夹标记为资源根?

node.js - npm install dependencies 在带有共享文件夹的 vagrant ubuntu 中失败

intellij-idea - 如何在intellij-idea/phpstorm中选择单词结尾