vagrant Xdebugメモ

symfony2 vagrant デバッグメモ

symfony2 + vagrant + phpStormでのデバッグ設定 なぜかなかなか動かなかったのでメモ

vagant側設定(centOS7)

repositoryの準備 sudo yum install -y epel-release sudo yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

xdebugのインストール sudo yum --enablerepo=remi,remi-php56 install -y php php-mysqlnd php-opcache php-mbstring php-gd php-mcrypt php-xml php-pear php-devel php-xmlrpc php-pecl-apcu php-pecl-xdebug

php -v

xdebugの確認

php -v PHP 5.6.26 (cli) (built: Sep 15 2016 14:46:18) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans

with Xdebugが出ることを確認する

php.iniの編集

xdebug.remote_connect_back = On xdebug.remote_enable = On xdebug.remote_autostart = On xdebug.remote_host = 192.168.33.11 xdebug.remote_port="9001" xdebug.profiler_enable= On xdebug.max_nesting_level=1000 xdebug.idekey = "PHPSTORM"

xdebug.remote_host はクライアント側(vagrant)で指定したIP

Vagrantfileで下記のように指定している奴 config.vm.network "private_network", ip: "192.168.33.11" idekeyはメモっておく

IDE(phpStorm)側設定

Run → Edit configuration +を押して、php Remote debugを押下 登録名は適宜 ide key はphp.iniに記載したやつにする(今回はPHPSTORM) サーバーは未登録の場合横の …から設定できる。

Nameは適宜、Hostはiniのxdebug.remote_hostと同じやつ、ポートは使っているやつ DebuggerはXdebugを選択し、OKで登録

rsyncを使っている場合はUse path mappingsをチェックし、左側にホスト側のソースの場所、右側にvagrant側の同期箇所を記載(config.vm.synced_folderで記載しているやつ)

今回例だと他のバッティングしたのでxdebugのポートを通常の9000から9001に変更しているので設定の変更が必要 xdebug.remote_port="9001"

phpStorm→preferance→ langguage & frameworks → PHP → Debug → Xdebugからdebug port を9000から9001に変更 (prefernceから 左上の検索欄からxdebugした方が早い)

適当にbreakpointを設定し、Run "debug名"をクリックし、監視 phpにアクセスし、ちゃんと止まったらOK

記事を検索するとini設定の仕方が結構様々なのでよくワカラナイ。 自分の設定ではxdebug.remote_connect_back = On がないとちゃんと止まらなかった。 あとphpStorm7であるserver設定登録時"Validate Remote Environment"ボタンは現在最新(10)ではRun→web server validationに場所が移ったみたい。