VS Code + Laravel Homestead + XDebugでデバック環境構築

VS Code + Laravel Homestead + XDebugでデバック環境構築を構築しようとしましたが、ハマったしまったのでメモ。

 

私の環境

  • Windows 10 Pro
  • Vagrant 2.1.2
  • Homestead v7.2.1
  • PHP 7.2.5 (Homesteadデフォルトのバージョン)
  • XDebug v2.6.0 (Homesteadデフォルトのバージョン)

 

基本的には下記のページを参考にしました。

Directions for debugging using Xdebug, VSCode, and Homestead. · GitHub 

Homestead Laravel Xdebug · Issue #220 · felixfbecker/vscode-php-debug · GitHub

 

/etc/php/7.2/fpm/conf.d/20-xdebug.ini の設定は

zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_host=10.0.2.2
xdebug.remote_autostart = 1

のみです。

xdebug.remote_connect_back = 1

が書いてあったら消しておく。

 

VSCodeのlaunch.jsonの設定は下記の通り。

(私の保存場所はD:\workspace\laravel_work\.vscode\launch.jsonです。)

{
"name": "Homestead",
"type": "php",
"request": "launch",
"pathMappings": {
"/home/vagrant/code": "${workspaceRoot}" //←これは動く
// "/home/vagrant/code": "D:/workspace/laravel_work" //←これでは動かない
// 追記2018.7.23 下記の設定でも動作する
// "/home/vagrant/code": "D:\\workspace\\laravel_work" //←これは動く
},
"port": 9000
}

 

 Homestead.yamlの設定を一部抜粋

folders:
  - map: D:\workspace\laravel_work
   to: /home/vagrant/code

私の環境では${workspaceRoot}はD:/workspace/laravel_workになるはずですが

 pathMappingsの設定を上記コメントアウトの設定ではなぜか動かず。

${workspaceRoot}にしたところデバッカが動いた。