LoginSignup
6
9

More than 5 years have passed since last update.

PhpStormでVirtualBox:CentOS7開発環境のリモートデバッグ!

Last updated at Posted at 2017-04-25

※備忘録的な記事なので詳細省いてます。すんません。

こんな方向け

プログラムをローカル環境で書いて、それをVM開発環境にアップして動作確認している方

環境

ローカル

  • Mac OS X Yosemite(10.10.5)
  • PhpStorm 2016.2.1

VM開発環境

  • VirtualBox 4.3.28
  • CentOS 7.3.1611
  • PHP 5.4
  • Xdebug 2.2.0

設定

まずは開発環境の設定

VM環境にて必要なパッケージのインストールを行なう

bash
$ sudo yum install php-pear
$ sudo yum install php-devel
$ sudo yum install gcc gcc-c++ autoconf automake
$ sudo pecl install xdebug-2.2.0 (バージョン指定しないと最新版をインストールしようとするが、最新版はPHP5.4に対応していないのでエラーとなる)

php.iniに追記

php.ini
...

[Xdebug]
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.defaul_enable=1
xdebug.remote_enable=1
xdebug.remote_host='127.0.0.1' ## ローカルを指定している
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.max_nesting_level=1000
xdebug.idekey='PHPSTORM'

※たぶん重複してるのとか、要らない設定書いてる気がします。。。

サーバー再起動

bash
sudo systemctl restart httpd.service

次にローカルのPhpStorm上での設定

PhpStormメニュー > Preferences にて、

  • Languages $ Frameworks > PHP
    • Debug メニュー
      • XdebugエリアのDebug port のポート番号を、先ほどVMで設定した番号と同じものにする(デフォルトで9000)
    • Servers メニュー
      1. + ボタンで追加
      2. Name: にて好きな名前を入力
      3. Host にVM開発環境のIPアドレスを入力
      4. Debugger セレクトメニューで Xdebug を選択
      5. File/Directory にてローカルのプロジェクトフォルダを指定
      6. Absolute path on the server にてVM開発環境のプロジェクト絶対パスを入力
      7. Apply ボタン、OK ボタンをクリックして追加完了
  • Run メニュー > Edit Configurations... にて
    1. + ボタンで設定追加
      • Add New Configuration として小さなウィンドウが開くので、そこから PHP Remote Debug を選択
    2. Name: に好きな名前を入力
    3. Servers: に先ほどPreferences にて追加したサーバーを選択する
    4. Ide Key(session id): に、VM開発環境のphp.iniに記載したideKey(この例の場合はPHPSTORM)と同じものを入力
    5. Apply ボタン、OK ボタンをクリックし追加完了

デバッグ実行

  1. 好きなブラウザでVM開発環境の該当ページにアクセスしておく
  2. PhpStormにて、1.に該当するプロジェクトファイルを開いておく
  3. 2.のファイルでブレークポイントを設定する
  4. PhpStorm の Run メニュー > Start Listening for PHP Debug Connections(もしくはエディタ画面右上にある電話機のようなマーク)をクリック
  5. 1.のページをリロードする
  6. PhpStorm画面下部でDebug画面が開き、デバッグ詳細を確認できる

あとがき

時間が出来たら詳細記載・修正追記します。

6
9
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
6
9