0
1

More than 3 years have passed since last update.

Vagrant + PHP + IntelliJ IDEA でリモートデバッグを設定

Posted at

Vagrant側の設定

サーバーにログイン

vagrant ssh

peclコマンドをインストール

(php7の場合、pearのバージョンは1.10.0以降でないと上手く動かない)

sudo yum --enablerepo=remi-php70 install php-pear

pear -V
PEAR Version: 1.10.5
PHP Version: 7.0.11
Zend Engine Version: 3.0.0

xdebug インストール

pecl install xdebug

You should add "zend_extension=/usr/lib64/php/modules/xdebug.so" to php.ini  

php.iniにパラメータを設定

zend_extension=xdebug.so          ← Apacheの場合はフルパス指定「/usr/lib64/php/modules/xdebug.so」  
xdebug.remote_enable = On  
xdebug.remote_connect_back = On  
xdebug.remote_autostart = On  
xdebug.remote_host = 192.168.33.1  ← echo $_SERVER["REMOTE_ADDR"]; の値  
xdebug.remote_port = 9001          ← ローカルPCにて lsof -i :9001 コマンドを使用し、使用されていないポートか確認  
xdebug.idekey="HOGEhoge"           ← IDE側の設定で使用する  

環境変数PHP_IDE_CONFIGを設定

Apache

SetEnv PHP_IDE_CONFIG serverName=FUGAfuga

nginx

fastcgi_param PHP_IDE_CONFIG serverName=FUGAfuga;

cliで実行する場合

vagrantユーザーの~/.bashrc に設定

export PHP_IDE_CONFIG="serverName=FUGAfuga"
source .bashrc

サーバー再起動

nginx

sudo service nginx restart
sudo service php-fpm restart

Apache

sudo service httpd restart

設定を確認

php -i | grep xdebug

IDE側の設定

接続するリモートホストを設定する

  1. RUN → Edit Configurations を選択
  2. ダイアログ左上にある「+」を押下し、PHP Remote Debugを選択 Edit_Configurations.png php_remote_debug.png
  3. Serversの「...」を押下し、Serversダイアログを表示
    Servers1.png
  4. Serversを設定
    Name : PHP_IDE_CONFIG serverName=で指定した値(FUGAfuga)
    Host、Port : vagrant ssh-config コマンドで確認
    Debugger : Xdebug
    Use Path mappings をチェックし、ローカルとリモートホストでシンクしているディレクトリを設定
    Servers_設定.png Preferences → PHP → Debug よりXdebugのポートを設定
    Preference.png Ide keyを設定(HOGEhoge)
    Name を設定 (わかりやすいサービス名、Vagrant) Servers2.png
  5. RUN → Break at first line in PHP scripts にチェック
    (デバッグが動作するとき、必ず最初の1行目でブレークポイントが走る)

  6. RUN → Start Listening for PHP Debug Connections をチェック

    ブレークポイントをはり、処理の途中でデバッグができるようになりました。
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