VSCodeでPHPをXDebugするのに苦戦したので備忘録
WSL2 & Docker 前提です。
xdebug.ini
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal
xdebug.client_port={PORT}
docker-compose.yml
web:
# ...
extra_hosts:
- "host.docker.internal:host-gateway"
.vscode/launch.json
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": {PORT}, //xdebugのiniポートと合わせる
"pathMappings": {
"/var/www/html": "${workspaceFolder}" // Dockerコンテナ内のウェブルートパス
}
},
反映されない場合はビルドし直すとよい
docker compose up -d --build