Laravel Sail + Xdebug + VS Codeでのデバッグ


  • sail artisan sail:publish を実行して Dockerfile を出す。
  • Dockerfileapt-get install -y php-xdebug を差し込む。
  • php.ini に下記追加
[XDebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
  • sail build --no-cache を実行。
  • VS Codeに 拡張機能 PHP Debug を入れる。
  • .vscode/launch.json に下記設定を追加。
{
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "stopOnEntry": true,
    "port": 9003,
    "pathMappings": {
        "/var/www/html": "${workspaceFolder}"
    },
    "hostname": "localhost",
    "xdebugSettings": {
        "max_data": 65535,
        "show_hidden": 1,
        "max_children": 100,
        "max_depth": 5
    }
}
  • VSCodeにてデバッグ開始。 終わり。