LoginSignup
1
4

More than 3 years have passed since last update.

PHPStormでVirtualBoxのサーバーと連携してリモートデバッグ(Xdebug)の設定方法

Posted at

対象者

・開発環境がVirtualBoxにあってマウントしたソースコードを使ってPHPStormで開発を行なっている人

はじめに

バージョン

PHP v5.6
VirtualBox v6.0.12

xdebugのインストール

$ sudo yum install php-pear
$ sudo yum install php-devel
$ sudo yum install gcc gcc-c++ autoconf automake
$ sudo pecl install xdebug-2.2.5

xdebugのバージョンはPHPのバージョンに依存するため、PHPのバージョンを確認して使えるバージョンを指定してインストールしましょう!

$ sudo vim /etc/php.ini

php.iniの設定(Xdebug)

もしかしたら全部必要かわからないですが。。。

php.ini
・・・
[Xdebug]
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler = "dbgp"
xdebug.remote_mode = "req"
xdebug.remote_host='192.168.56.101'
xdebug.remote_port=9000
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/tmp"
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.max_nesting_level=1000
xdebug.remote_log=/var/log/xdebug.log
xdebug.idekey='PHPSTORM'

PHPStormの設定1

・Preferences...を選択
-Language&Frameworksを選択
-PHPを選択
-Debugを選択
-Serversを選択
-"+"で新しく作成
・Nameは任意の名前を入力しましょう
・Host名はVirtualBoxのサーバー接続時のIP番号を入力(php.iniのxdebug.remote_hostで指定したIP)
・Port名はphp.iniで指定したポートを入力(php.iniのxdebug.remote_portで指定したポート)
・DebuggerはXdebugを選択
・VirtualBoxのサーバー上とローカル環境でフォルダをシンクさせている場合は、Use path mappingsにチェックを入れ、シンクしているディレクトリを選択。(Absolute path on the serverにVirtualBoxのサーバー上にある開発プロジェクトのルートディレクトリを指定してやりましょう)
・ApplyしてOK

PHPStormの設定2

・Runを選択
・Edit Configurations...
-"+"で新しく作成
-PHP Remote Debugを選択
-Nameに任意の名前を入力
-Serverに先ほど作成したServerを指定
-IDE key(session id)には、PHPSTORMと入力(php.iniのxdebug.idekeyで指定したキー)
・ApplyしてOK

リモートPHPインタプリタの設定

・Preferences...を選択
-Language&Frameworksを選択
-PHPを選択
CLI Interpreterを設定
自分の場合はデフォルトでPHP7.1があったのでそれを設定
・ApplyしてOK

デバッグ

・デバッグしたいページを開いておく。
・PHPStormでそのデバッグに使うソースコードを開いてブレークポイントを指定
・Runを選択
-Start Listening for PHP Debug Connectionsを選択
・ページをリロード
この時にPHPStorm側で左下のDebugを選択してVariablesに各変数の値が出てればOK!

まとめ

仕事で設定したので備忘録として残しました〜。

参考

[PHP] Xdebug のリモートデバッグ、理解していますか?
PhpStormでVirtualBox:CentOS7開発環境のリモートデバッグ!
PhpStormでXdebugを使えるようにしよう!
エンジニア婦人ノート VSCodeを使おう!-XAMPP×XDebug×PHP-
Xdebugの設定(PHPStorm公式リファレンス)

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