0
1

More than 3 years have passed since last update.

PhpstomでのDockerローカル環境の開発におけるXdebugの設定手順

Last updated at Posted at 2021-08-23

概要

表題の通り、PHPのDockerの開発環境でデバッグを行いたかったため、設定手順を残す

環境

  • macOS Big Sur (Version 11.4)
  • PhpStorm 2021.2
  • Docker Desktop for Mac(2021-08-23 時点の最新)
  • PHP 8.0.0RC5
  • Xdebug v3.0.4

手順

Xdebug設定ファイルの追加

php.ini等設定ファイルを格納しているディレクトリにxdebugのiniファイルを作成する
※ php.iniを直接編集してもよいが、設定内容をわかりやすくするため分ける

xdebug-local.ini
[xdebug]
xdebug.idekey = phpstorm # 任意の名前
;xdebug.mode = off # 無効化する際はoffに書き換えて再ビルドする必要がある
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal

Dockerfile修正

Xdebugインストール&有効化と設定ファイルコピーの記載を付け加える

RUN pecl install xdebug-3.0.4 \
    && docker-php-ext-enable xdebug

COPY docker/xdebug-local.ini /usr/local/etc/php/conf.d/xdebug.ini

アプリケーションコンテナの再ビルド

$ docker-compose build --no-cache {container_name}

Phpstormでの設定

1.Serversの設定
Preference(⌘ + ,) -> PHP -> Servers を開き、左上+ボタンからサーバを追加し、以下を入力

  • Name: 任意
  • Host: locahost
  • Port: phpアプリケーションコンテナと紐付けを行っているport(docker-composeであれば、docker-compose.yamlのportsに記載があるはず)
  • Debugger: Xdebug
  • Projectfilesのマッピング(Absolute path on the server): /var/www/html

2.Edit Configurationsの設定

上部プルダウンからEdit Configurationsをクリック
image.png

以下を入力

  • Server: 上記で作成したServer
  • IDE key: xdebug-local.iniで設定したidekey

動作確認

コンテナを起動

$ docker-compose up

Phpstormの上部のデバッグマークをクリック
image.png

任意のリクエストを行い、デバッグに成功すれば終了
※リクエスト時、Phpstom上でアクセス許可ダイアログが出る場合、Acceptする

0
1
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
1