【问题标题】:Configuring Laravel Homestead (Vagrant) and xdebug on Visual Code在 Visual Code 上配置 Laravel Homestead (Vagrant) 和 xdebug
【发布时间】:2017-12-14 06:59:33
【问题描述】:

我一直在尝试使用“PHP Debug”扩展在 VSCode 上配置 xDebug,以与我当地的 Homestead 一起工作。不知何故,它根本不起作用。我一直在尝试不同的配置更改,但没有成功。

这是我在 Vagrant box 和 VSCode 中的配置:

/etc/php/7.1/fpm/conf.d/20-xdebug.ini
zend_extension=/usr/lib/php/20160303/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.remote_host = 192.168.0.104
xdebug.remote_port = 9000
xdebug.max_nesting_level = 512
xdebug.remote_handler = "dbgp"
xdebug.remote_log=/var/log/xdebug.log

这是我在 VSCode 中的配置:

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "serverSourceRoot": "/home/vagrant/projects/Projectname",
            "localSourceRoot": "${workspaceRoot}",            
            "port": 9000,
            "log": true
        }
    ]
}

当我在 VSCode 中启动调试会话时,我会在调试窗口中看到以下输出:

<- launchResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true }

但是在运行我的应用程序时,它不会在我的任何断点处停止。

知道什么地方出了问题吗?我是否需要将 VM 的任何端口映射到 Homestead.yaml 中的主机?

【问题讨论】:

    标签: visual-studio-code xdebug homestead


    【解决方案1】:

    我知道我回答这个问题迟了,但也许这篇文章可以帮助其他人节省时间:

    我能够使用 vagrant 在 PHP 代码 VSCode 中进行调试,执行以下步骤:

    1. 安装VSCode扩展"PHP Debug"
    2. 编辑"launch.json" 文件:

      {
        "version": "0.2.0",
        "configurations": [
            {
               "name": "Listen for XDebug",
               "type": "php",
               "request": "launch",
               "port": 9000,
               "localSourceRoot": "/your/host/php/dev/path/to/project-name",
               "serverSourceRoot": "/home/vagrant/dev/project-name"
            },
            {
               "name": "Launch currently open script",
               "type": "php",
               "request": "launch",
               "program": "${file}",
               "cwd": "${fileDirname}",
               "port": 9000
            }
         ]
      }
      
    3. 通过 ssh 连接到正在执行的宅基地机器 vagrant ssh

    4. 进入文件夹

      cd /etc/php/7.1/fpm/conf.d/

    5. 编辑文件“20-xdebug.ini”并验证端口 9000 是否已配置

      执行sudo vim 20-xdebug.ini

      编辑行:

      xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_connect_back = 1 xdebug.max_nesting_level = 500 xdebug.remote_port = 9000

    6. 保存并退出。

      按 [退出] 键。 类型:SHIFT Z Z

    7. 重启PHP 执行: sudo service php7.1-fpm restart

    希望对你有帮助!

    【讨论】:

    • 这会导致缺少属性请求。所选调试配置中缺少属性“请求”。
    • localSourceRoot 和 serverSourceRoot 已弃用。而不是:“localSourceRoot”:“/your/host/php/dev/path/to/project-name”,“serverSourceRoot”:“/home/vagrant/dev/project-name”使用:“pathMappings”:{“ "/home/vagrant/dev/project-name"" : "/your/host/php/dev/path/to/project-name" }
    猜你喜欢
    • 2017-04-18
    • 1970-01-01
    • 2021-05-28
    • 2018-03-03
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 2019-07-09
    相关资源
    最近更新 更多