LoginSignup
9
8

More than 1 year has passed since last update.

Xdebug ブレークポイントで止まらない!

Last updated at Posted at 2021-09-03

vscodeとxdegugで快適なデバッグ生活を送りたいと思いググりながら設定したのにブレークポイントで止まらない!

ハマった所をQiitaに残します

環境

Mac上にdocker環境を構築。

  • docker
  • php-fpm (PHP v8.0.8)
  • xDegug v3.0,4
  • laravel 8

php-fpmのコンテナにxdebugを入れる
(今回は直接コンテナ入って実行してます)

apk add autoconf build-base
pecl install xdebug
docker-php-ext-enable xdebug

xdebugの設定でまずハマる!

google先生に「vscode xdebug docker」等ででググるとxcodeのv2系の記事がヒットします。

このような設定が書かれています。

php.ini
[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9001
xdebug.remote_log=/tmp/xdebug.log

が、Xdebugのv3系だとパラメータ名が変わってました!

php.ini
[xdebug]
xdebug.mode=debug
xdebug.start_with_request = yes
xdebug.client_host=host.docker.internal
xdebug.client_port=9013
xdebug.discover_client_host = 1

インストールされてるXdebugのバージョンをよく確認しましょう。

/var/www # php -v
PHP 8.0.8 (cli) (built: Jul  1 2021 22:58:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

vscodeのlaunch.jsonでハマる

vscodeにまずはPHP Degugを入れる
image.png

左の実行とデバッグからlaunch.jsonを編集
image.png

launch.json

launch.json
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9013,
            "pathMappings": {
                "/var/www": "${workspaceRoot}/laravel"
            }
        },

「pathMappings」ですが、「ドキュメントルート」を指定するという記事を見て混乱しました。
ここはドキュメントルートではなく、ローカルとコンテナ側でマウントしている同じパスをマッピングすれば良さそうでした。

ブレークポイントを置いてブラウザでアクセス

あとは、ブレークポイントを置いてブラウザでページを開けばちゃんと止まる。

vscode.gif

これで快適なデバッグ生活ができそうです

9
8
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
9
8