LoginSignup
4
6

More than 5 years have passed since last update.

Homestead環境においてPhpStormからPHPUnitをデバッグ実行する

Posted at

環境

  • php 7.2
  • Laravel 5.4
  • Homestead 6.1.0 (Vagrant経由で起動)
  • Windows10(Homesteadとの共有フォルダを作成してWindows上でソースを編集している)
  • PhpStorm 182.3911.43
  • xdebug 2.6.0

やりたい事

PhpStormからPHPUnitをデバッグ実行したい
(ブレークポイントで停止させたい)

手順

1. Homestead上でxdebugの設定を行う

/etc/php/7.2/mods-available/xdebug.iniを以下の通り編集する

zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 512
xdebug.remote_autostart = 1 # ←追加
xdebug.remote_host = 10.0.2.2 # ←追加(Homesteadでは10.0.2.2がホストOSのIPアドレスになります)

2. php-cliでxdebugを読み込む様に設定する

cd /etc/php/7.2/cli/conf.d
sudo ln -s /etc/php/7.2/mods-available/xdebug.ini 20-xdebug.ini

3. nginx, php-fpmを再起動する

設定を再読み込みするためです。

sudo service php7.2-fpm restart
sudo nginx -s reload

4. PhpStormで設定画面を開き、xdebugからの接続を待ち受けるポートを設定します

Ctrl+Alt+Sで設定を開く
Serversを選択する(下記画像中①)
ボタンを押下して設定を追加する(下記画像中②)
Host: 127.0.0.1 (下記画像③)
Port: 9000 (下記画像③)
Use path mappings にチェックを入れる (下記画像④)

image.png

確認

エディター上でブレークポイントを設定後
PHPUnitをデバッグ実行する
ブレークポイントの行で停止すればOKです

image.png

参考ページ

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