在可视代码上配置Laravel Homestead(Vagrant)和xdebug

问题描述:

我一直试图在VSCode上配置xDebug,并使用“PHP Debug”扩展与本地Homestead配合使用。不知何故,它根本不起作用。我一直在尝试不同的配置更改,但没有成功。在可视代码上配置Laravel Homestead(Vagrant)和xdebug

这里是我在流浪框和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 } 

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

有什么想法可能是错的?我需要将我的虚拟机的任何端口映射到Homestead.yaml的主机上吗?

我知道我来晚来回答这个问题,但也许这篇文章可以帮助别人节省时间:

我能够使用的流浪汉做以下步骤在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. 保存并退出。

    按下[Escape]键。 类型:SHIFT Z Z

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

希望它能帮助!