まずはじめに、Visual Studio Code と XAMPP Lite をインストールします。XAMPP Lite をインストールした後、XAMPP Lite の php.ini に下記を追記します。
※ XAMPP は D フォルダ配下にインストールしています。
また、D:\xampp\php\ext に php_xdebug-<バージョン>-.dll を配置しています。php_xdebug.dll のバージョン特定方法は、こちらの記事を参考にさせてもらいました。
D:xampp\php\php.ini に次のコードを追記します。
[XDebug] zend_extension="D:\xampp\php\ext\php_xdebug-2.7.2-7.1-vc14.dll" ;xdebug.remote_enable=On xdebug.remote_enable=1 xdebug.remote_autostart=1 xdebug.remote_host="localhost" xdebug.remote_port=9000 xdebug.remote_handler=dbgp
D:xampp\htdocs\.vscodelaunch.json に次のコードを追加します。
{ "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9000 }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9000 } ] }
"Listen for XDebug" でデバッグ実行をすると、php ファイル上で設定したブレークポイントで処理を止めることができます。
