PHP配置xdebug的方法
一、 查看PHP对应的xdebug版本并下载
1、创建一个php文件,文件内容如下图,将这个文件放到Apache服务器访问根目录下
2、重浏览器输入本地地址访问Apache服务器,查看相应的PHP版本
3、将这个页面显示所有信息复制,访问网址https://xdebug.org/wizard.php,并将复制的信息粘贴到文本框里,点击下方的Analyse my phpinfo() output按钮
4、下载其建议的dll文件
5、将下载的文件放到PHP的安装目录下的ext文件夹下,我这里用的是xampp集成软件
6、找到PHP目录下的php.ini文件并打开,在文件内容最后一行下面输入
[xdebug]
zend_extension = D:\xampp\php\ext\php_xdebug-2.9.6-7.3-vc15.dll //这个路径是刚才下载的那个dll文件存放的路径
xdebug.remote_enable=on
xdebug.remote_autostart=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.romote_host=localhost
xdebug.remote_port=9000
7、在vscode上搜索phpdebug插件并安装
8、打开launch.json文件并配置参数
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"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
}
]
}
9、打开VScode的设置"php.validate.executablePath": "D:\\xampp\\php\\php.exe",//这里是你php安装目录下的文件,如果没有内容就添加进去,如果有就修改
10、启动xdebug,从浏览器访问你的项目,会跳转到你的代码,说明就成功了,你就可以利用php的调试查找你的代码的错误