PhpStormでXDebugを使いデバッグ : PHP

Pocket

PhpStormはXDebugを使いステップ実行などデバッグをすることができます。MacへのXDebugのインストールおよびXDebug、PhpStormの設定を記載しています。

  1. XDebug設定
  2. PhpStorm設定

1. XDebug設定

インストール

$ brew install php56-xdebug

設定ファイル

下記コマンドで設定ファイルの場所を確認できます。

$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/5.6
Loaded Configuration File:         /usr/local/etc/php/5.6/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d
Additional .ini files parsed:      /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini <----- XDebug設定ファイルです。

記載例です。

[xdebug]
zend_extension="/usr/local/opt/php56-xdebug/xdebug.so"
xdebug.remote_enable=1
;xdebug.remote_port="9000"
xdebug.remote_port=10000
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/path/to/output"                                                                                       

デフォルトはxdebug.remote_port=9000です。
エラーが発生するときは他のアプリケーションが9000を利用している可能性があります。
xdebug.remote_portを9000以外へ変更します(例は10000に変更しています)。

Can not start listening for connections from 'xdebug': Port 9000 is busy

デバッグの際に下記エラーの発生する環境がありました。

14:29   Debug session was finished without being paused
            It may be caused by path mappings misconfiguration or not synchronized local and remote projects.
            To figure out the problem check path mappings configuration for 'localhost (1)' server at PHP|Servers or enable Break at first line in PHP scripts option (from Run menu).
            Do not show again

下記のように設定ファイルを変更し解消しました。
ext-xdebug.iniを変更

xdebug.default_enable = 1
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_port=9001
;xdebug.profiler_enable=1
xdebug.profiler_output_dir="/path/to/output"
; xdebug.remote_host=localhost
xdebug.max_nesting_level=10000
xdebug.remote_connect_back=1
xdebug.idekey = "PHPSTORM"

xdebug.max_nesting_level=10000が小さいと発生する可能性が高いと感じていますが、検証はできていません。

PhpStorm

preference > Languages & Frameworks > PHP > Debug
XdebugセクションのDebug portを/usr/local/etc/php/5.6/conf.d/ext-xdebug.iniへ記載したポートを設定します。

PhpStormのドキュメントでは他の設定項目について記載がありますが、
上記設定以外の設定はせずブレークポイントを貼り電話アイコンクリックしリッスン状態にすれば、
初回アクセス時にダイアログが表示され自動で設定されます。

自動セットアップで設定される項目

自動で設定される項目下記のとおりです。

  • preference > Languages & Frameworks > PHP
    設定なし(interpreterも指定しません)
  • preference > Languages & Frameworks > PHP > Debug
  • preference > Languages & Frameworks > Servers
    Host localhost Port 8080 Debugger XDebug

コメント

No comments yet.

コメントの投稿

改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。