0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

xdebugを設定する方法

Posted at

ただの備忘録として、ここに記載する。

使用するファイル/前提の環境

  • php.ini
  • launch.json
  • docker

手順

  1. backend配下に、php/conf.dev.d/php.iniのファイルを作成
    ファイルに以下を記載

    xdebug.mode=debug
    xdebug.start_with_request=yes
    xdebug.client_host=host.docker.internal
    xdebug.client_port=9003
    

    ※xdebug2の書き方になるので、もしxdebug3を使用する場合は異なる

    • xdebug.mode=debug → デバッグモードを有効化
    • xdebug.start_with_request=yes → リクエストごとにXdebugを開始
    • xdebug.client_host=host.docker.internal → Dockerコンテナ内のPHPがホストマシンに接続
    • xdebug.client_port=9003 → VS Codeのリスナーポート
  2. launch.jsonに以下を追記

        "configurations": [
            {
                "name": "XDebug on docker",
                "type": "php",
                "request": "launch",
                "port": 9003,
                "pathMappings": {
                  "/var/task": "${workspaceRoot}/backend"
                }
            }
        ]
    
    • port番号をphp.iniと合わせる

    • pathMappingsについては、コンテナ内のパスとホストマシン(ローカル)のパスを紐付ける。VSCodeのデバック時に、どのファイルがどこにあるかを正しく認識できるようにしている。

    • docker-compose.ymlで、コンテナ内のどこにマッピングをしているかわかる。
      backendサービスが/var/taskに./backendをマッピングしている

        backend:
          image: bref/php-83-fpm-dev:2.3.10
          platform: linux/x86_64
          ports:
            - 8080:8000
          volumes:
            - ./backend:/var/task
            - ./backend/storage:/tmp/storage
          tty: true
          environment:
            HANDLER: public/index.php
            DOCUMENT_ROOT: public
            AWS_ACCESS_KEY_ID: minio
            AWS_SECRET_ACCESS_KEY: minio123
      
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?