php 程序开发,xdebug 比不可少,记录下配置流程。
phpstudy
phpstudy 在 php 环境集成的 xdebug,直接将插件开启即可使用。
phpstudy-> 软件管理 -> 全部 ->php-> 设置,开启 xdebug 调试组件,并设置端口。

vscode
在项目根目录下,建立用户自定义配置。vscode 的所有配置,均在在此设置,这样,每个项目可以配置不同的环境和配色等。
.vscode/settings.json
这块写自己的开启了 xdebug 插件的 php 路径
{
"php.validate.executablePath":"*//php.exe",
"php.debug.executablePath":"*//php.exe",
"php.debug.ideKey": "vsc"
}
php.debug.executablePath
:debug 调用的 php 环境
php.debug.ideKey
: 执行唤起 ide 的 xdebug 终端关键字,此配置需要 php.ini
中配置一致。
配置此项,可忽略 xdebug.remote_host
配置
php.ini
zend_extension=D:/web/serve/phpstudy_pro/Extensions/php/php7.1.9nts/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=Off
xdebug.trace_output_dir=D:/web/serve/phpstudy_pro/Extensions/php_log/php7.1.9nts.xdebug.trace
xdebug.profiler_enable=Off
xdebug.profiler_output_dir=D:/web/serve/phpstudy_pro/Extensions/php_log/php7.1.9nts.xdebug.profiler
xdebug.remote_enable=1
xdebug.remote_autostart = 1
xdebug.idekey=vsc
;xdebug.remote_host=m.zmyy.tf
xdebug.remote_port=9100
xdebug.remote_handler=dbgp
大部分是自动生成的配置,注意 idekey
、remote_host
、remote_port
三项配置即可。
配置完毕,测试效果
在需要调试的代码行打断点

按 F5 启动调试,vscdode 会提示配置,launch.json 文件,用于发起调试
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9100
},

访问 php 端程序,发现程序到断点处停了下来,开始愉快的调试吧。

分享一下vscode的个人配置
.vscode/settings.json
排除文件显示
{
"files.exclude": {
"**/.DS_Store": true,
"**/__init__.py": true,
"**/__pycache__": true,
},
}
代码自动换行,显示代码长度标尺线
{
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 120,
"editor.rulers": [
80,
120
],
}
编辑器的高亮配置
{
"workbench.colorCustomizations": {
// "editor.background": "#363636", //编辑器背景色
"editor.lineHighlightBackground": "#49b2b93d", //修改光标所在行的背景色
"editor.lineHighlightBorder": "#ffffff30", //修改光标所在行的边框色
"editor.selectionBackground": "#49b2b93d", //是选中后拖拉呈现的颜色
"editor.findMatchBackground": "#511F90", //当前搜索匹配的颜色
"editor.findMatchHighlightBackground": "#fd5000", //其他搜索匹配项的颜色
"editor.findRangeHighlightBackground": "#ff9900", //限制搜索范围的颜色
"list.inactiveSelectionBackground": "#008000",
},
}
编辑器代码配色自定义
{
"editor.tokenColorCustomizations": {
"comments": "#708090", //春天绿
"keywords": "#c792eaff",
"strings": "#C3E88D"
},
}
本文作者:Fly
本文链接:https://www.xuehuafei.cn/archives/vscode-cooperates-with-phpstudy-to-start-xdebug.html
版权声明:白嫖注明出处