EC-CUBE4の環境構築続きです。
【EC-CUBE4】①EC-CUBE本体の開発環境を整える(インストール編)
【EC-CUBE4】②EC-CUBE本体の開発環境を整える(GitHub Flow編)
[【EC-CUBE4】③EC-CUBE本体の開発環境を整える(MYSQL,MailCatcher編)]
(https://qiita.com/junpeko5/items/3316b654b4b80ee59376)
[【EC-CUBE4】④EC-CUBE本体の開発環境を整える(Postgres,MailCatcher編)]
(https://qiita.com/junpeko5/items/ef572490c44da90eac59)
前提条件
- Mac
- .phpenvでphp7.2.8がインストール済み
- EC-CUBE4がローカル環境にインストール済み(【EC-CUBE4】①EC-CUBE本体の開発環境を整える(インストール編)が終わっていること)
方針
- webサーバーはビルドインウェブサーバーを利用。
xdebugのモジュールを有効にする
$ php -S localhost:8000
$ php -v
PHP 7.2.8 (cli) (built: Jun 19 2019 14:35:53) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.8, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.7.1, Copyright (c) 2002-2019, by Derick Rethans
$ php -m
[Zend Modules]
php -m
でXdebugのモジュールがなければ、エクステンションを有効にします。
まずは設定を確認します。
$ php --ini
Configuration File (php.ini) Path: /Users/<ユーザー名>/.phpenv/versions/7.2.8/etc
Loaded Configuration File: /Users/<ユーザー名>/.phpenv/versions/7.2.8/etc/php.ini
Scan for additional .ini files in: /Users/<ユーザー名>/.phpenv/versions/7.2.8/etc/conf.d
Additional .ini files parsed: /Users/<ユーザー名>/.phpenv/versions/7.2.8/etc/conf.d/xdebug.ini
$ vim /Users/<ユーザー名>/.phpenv/versions/7.2.8/etc/conf.d/xdebug.ini
xdebug.iniに以下を追記します。
[Xdebug]
xdebug.remote_enable=true
xdebug.remote_autostart = On
xdebug.remote_port=9001
xdebug.remote_host=localhost
xdebug.idekey = "PHPSTORM"
サーバーを再起動します。
$ php -S localhost:8000
$ php -m
[Zend Modules]
Xdebug
Xdebugのモジュールが表示されていればOKです。
PhpStormの設定
Preferences
Preferences > Languages & Frameworks > PHP より、CLI Interpreterを設定します。
下図のような感じです。

CLI Interpreterが設定されました。

次に、
Preferences > Languages & Frameworks > PHP > Debug より、Debug portを9001に設定します。

Preferences > Languages & Frameworks > PHP > Servers より、下図のように設定します。

Edit Configurations
Edit Configurationsを設定します。
Run > Edit Configurations より、ServerとIDE keyを設定します。

動作確認
PhpStorm右上の電話マークをオンにしてください。
その後、図のようにソースの左側にブレークポイントを張って、ブラウザで、画面遷移します。
処理が走ると、ブレークポイントで処理が止まります。
下図のようになれば、デバッグが成功しています。

注意点
EC-CUBE4の管理画面からプラグインをインストールする際に、Xdebugが有効になっているとインストールに失敗します。
プラグインをインストールする際は、Xdebugを無効にしてから、インストールするようにしましょう。