LoginSignup
14

More than 5 years have passed since last update.

Docker Toolbox、Laradock、PhpStorm環境のXdebug設定手順

Posted at

Xdebugの設定手順を書いた投稿は多いですが、自分の環境に合った方法が少なく、設定に手こずったので同じ環境の人向けに残しておきます。

目次

  1. Laradockの設定
  2. PhpStormの設定
  3. 動作確認

環境

  • Windows10 Home
  • Docker Toolbox
  • Laradock
  • PhpStorm

1. Laradockの設定

まずLaradockの設定を行います。

$ vi .env
.env
#WORKSPACE_INSTALL_XDEBUG=false
WORKSPACE_INSTALL_XDEBUG=true

#PHP_FPM_INSTALL_XDEBUG=false  
PHP_FPM_INSTALL_XDEBUG=true  
$ vi workspace/xdebug.ini
workspace/xdebug.ini,php-fpm/xdebug.ini
; xdebug.remote_host=dockerhost
xdebug.remote_host=192.168.99.1
#xdebug.remote_connect_back=1
xdebug.remote_connect_back=0
#xdebug.remote_port=9000
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM

#xdebug.remote_autostart=0
xdebug.remote_autostart=1
#xdebug.remote_enable=0
xdebug.remote_enable=1
#xdebug.cli_color=0
xdebug.cli_color=1
xdebug.profiler_enable=0
xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"

xdebug.remote_handler=dbgp
xdebug.remote_mode=req

xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1

同じ設定をphp-fpmのxdebugでも行います。

$ vi php-fpm/xdebug.ini

設定が完了したら、イメージを再構築して起動してください。

$ docker-compose up -d --build nginx mysql workspace 

2. PhpStormの設定

次にPhpStormの設定を行います。
ツールバーの[File][Settings...]を選択してください。
setting-phpstorm01.png

[Languages & Frameworks][Servers][+]を選択し、次のように設定を追加します。

setting-phpstorm02.png

  • Name: Laradock
  • Host: 192.168.99.100
  • Port: 80
  • Debugger: Xdebug
  • Use path mappings: チェックする
  • File/Directory: Laravelプロジェクトのフォルダ
  • Absolute path on the server: /var/www

[Languages & Frameworks][Debug][xdebug]のDebug portを変更します。

setting-phpstorm03.png

  • Debug port: 9001

3. 動作確認

デバッグしたい行の数字の右側をクリックすると赤い丸が表示されます。
この赤い丸はブレークポイントと呼ばれ、そこでプログラムが一旦停止します。

check01.png

次に右上の[虫マーク]を選択し、デバッグを実行した状態でブラウザにアクセスするとブレークポイントで停止されます。
PhpStormの下部のDebuggerに定数や変数が表示されれば設定完了です。
check02.png

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
14