vscode 使用phpstudy 和 PHP XDebug 无法运行及调试
1.1 表现症状
Vscode php debug F5后没有反应。
运行处也没有Debug调试,无法自动配置launch.json
1.2 使用步骤
- 先在vscode中安装PHP Debug,在
文件-首选项-设置
配置"php.validate.executablePath"项,填写对应版本的php.exe。
//填写你本地的php.exe路径
"php.validate.executablePath": "E:/tools/phpstudy_pro/Extensions/php/php7.3.4nts/php.exe",
- 按照
PHP Debug
插件的要求需要在php.ini
中进行如下配置
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
上述配置即打开XDebug调试组件,我本地为PHPStudy 在下图所示的位置配置好之后一定要再看一下php.ini
文件中是否上有上述两行代码
- 按F5调试,选择PHP,就可以了,可能会配置失败。
- 按 Ctrl+Shift+D 打开调试面板,点击上面的小齿轮打开launch.json,如果出现"Listen for XDebug"和"Launch currently open script",就证明成功了,如果没有出现 看解决方案~
1.3 解决方案
即按 1.2 操作后没有出现Listen for XDebug
和 Launch currently open script
,那么则需要手动添加
{
"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
}
1.4 结束
修复完成图
达到上图效果那么就可以调试了。