🐡
PHPスクリプトをVScodeでデバッグ実行する(macOS)
PHPとXdebugのインストール
brew install php
pecl install xdebug
❯ php -i | grep xdebug. | head
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support
Enabled Features (through 'xdebug.mode' setting)
'xdebug://gateway' pseudo-host support => no
'xdebug://nameserver' pseudo-host support => no
xdebug.auto_trace => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.cli_color => 0 => 0
xdebug.client_discovery_header => HTTP_X_FORWARDED_FOR,REMOTE_ADDR => HTTP_X_FORWARDED_FOR,REMOTE_ADDR
xdebug.client_host => localhost => localhost
xdebug.client_port => 9003 => 9003
xdebug.cloud_id => no value => no value
VScodeのXdebug拡張のインストール
プロジェクトの作成
mkdir php-app
cd php-app
touch index.php
code index.php
index.php
<?php
$greet = 'Hello World';
echo $greet;
launch.jsonの作成
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug current script in console",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"externalConsole": false,
"port": 9003,
"runtimeArgs": [
"-dxdebug.mode=debug",
],
}
]
}
デバッグの実行
- VScodeの左メニューの虫眼鏡マークをクリック(Ctrl+Shift+D)
- index.phpを選択
-
echo $greet;
の行にブレークポイントを設定 - F5キーを押す
- $greetの値を確認
Discussion