2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel9 + Sail + WSL2 + Ubuntu + VScodeでXdebugが使えない時

Last updated at Posted at 2022-05-12

現象

VScodeでブレークポイントを設定しても止まらない😥

構成

  • Windows10 Pro
  • WSL2
  • Ubuntu
  • Laravel9
  • PHP 8.1.5
  • Xdebug v3.1.2

解決方法1

VScodeのlaunch.jsonの設定に、pathMappingsに加え、hostnameを追記する

{
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}"
            },
            "hostname": "0.0.0.0", // ← これ
        }
    ]
}

解決方法2

初回のリクエスト時、URL(ブラウザでもAPIでも)に?XDEBUG_SESSION_START={xxx}を付加する
※セッションを閉じる場合はXDEBUG_SESSION_STOP

http://localhost:80/api/user?XDEBUG_SESSION_START=debug

その他設定

まだ使えない場合は、下記を確認👇

①.envにSAIL_XDEBUG_MODEが追加されているか

SAIL_XDEBUG_MODE=develop,debug

②docker-compose.ymlに**XDEBUG_~**の環境変数が設定されているか
※ 最新のLaravel9ではデフォルトで設定
※ 追加した場合は、再度ビルドが必要(sail build --no-cache

version: '3'
services:
    laravel.test:
        ~~~
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' # ← これ
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}' # ← これ
        ~~~

参考

本当に感謝です🙏
https://blog.shinki.net/posts/xdebug-not-work-docker-wsl

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?