Visual studio code 在可视化代码上配置Laravel Homestead(Vagrant)和xdebug

Visual studio code 在可视化代码上配置Laravel Homestead(Vagrant)和xdebug,visual-studio-code,xdebug,homestead,Visual Studio Code,Xdebug,Homestead,我一直在尝试在VSCode上使用“PHP调试”扩展配置xDebug,以便与我的本地家园一起工作。不知怎么的,它根本不起作用。我一直在尝试不同的配置更改,但没有成功 以下是我在Vagrant框和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 x

我一直在尝试在VSCode上使用“PHP调试”扩展配置xDebug,以便与我的本地家园一起工作。不知怎么的,它根本不起作用。我一直在尝试不同的配置更改,但没有成功

以下是我在Vagrant框和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
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中的配置:

/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
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 }

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

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

  • 安装VSCode扩展
    “PHP调试”
  • 编辑
    “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
          }
       ]
    }
    
  • 通过ssh连接到homestead机器
    vagrant ssh

  • 转到文件夹

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

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

    执行
    sudo vim 20 xdebug.ini

    编辑行:

    xdebug.remote\u enable=1
    xdebug.remote_autostart=1
    xdebug.remote\u connect\u back=1
    xdebug.max_嵌套水平=500
    xdebug.remote_端口=9000
    

  • 保存并退出

    按[退出]键。 类型:移位Z

  • 重新启动
    PHP
    执行:
    sudo服务php7.1-fpm重启


  • 希望有帮助

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

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

  • 安装VSCode扩展
    “PHP调试”
  • 编辑
    “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
          }
       ]
    }
    
  • 通过ssh连接到homestead机器
    vagrant ssh

  • 转到文件夹

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

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

    执行
    sudo vim 20 xdebug.ini

    编辑行:

    xdebug.remote\u enable=1
    xdebug.remote_autostart=1
    xdebug.remote\u connect\u back=1
    xdebug.max_嵌套水平=500
    xdebug.remote_端口=9000
    

  • 保存并退出

    按[退出]键。 类型:移位Z

  • 重新启动
    PHP
    执行:
    sudo服务php7.1-fpm重启


  • 希望有帮助

    这导致缺少属性请求。所选调试配置中缺少属性“Request”。不推荐使用localSourceRoot和serverSourceRoot。使用“路径映射”代替“localSourceRoot”:“/your/host/php/dev/path/to/project name”,“serverSourceRoot”:“/home/vagrant/dev/project name”使用:“{”“/home/vagrant/dev/project name”“:”/your/host/php/dev/path/to/project name”}这会导致缺少属性请求。所选调试配置中缺少属性“Request”。不推荐使用localSourceRoot和serverSourceRoot。代替“localSourceRoot”:“/your/host/php/dev/path/to/project name”,“serverSourceRoot”:“/home/vagrant/dev/project name”使用:“路径映射”:{”“/home/vagrant/dev/project name”“:“/your/host/php/dev/path/to/project name”}