前提:官网安装了PHP
一、检测是否有xdebug插件
![](https://img-blog.csdnimg.cn/direct/5f3c78783b254899a4a390bab220d0fb.png)
二、如果没有插件,下载对应版本的插件,并且配置php
1、查看自己php版本:
![](https://img-blog.csdnimg.cn/direct/239f4df9bb1e4169ac30705cd1531a09.png)
2、xdebug下载地址:
https://xdebug.org/download/historical
我下载的是箭头所示,和PHP版本号和系统对应
3、下载的插件放入php的ext目录,并且改个名字
![](https://img-blog.csdnimg.cn/direct/989b297d59e74b11aaf7e837de8ffde5.png)
4、复制一份php.ini-development,并且重重命名为php.ini![](https://img-blog.csdnimg.cn/direct/aa9d827118cb45e7a0301d3b51976589.png)
5、php.ini配置文件增加Xdebug插件配置:
zend_extension :换成自己的地址
c
[xdebug]
zend_extension="D:\software\php\php-8.3.8-Win32-vs16-x64\ext\php_xdebug.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.profiler_enable = yes
xdebug.client_host = localhost
xdebug.client_port = 9001
检测是否配置成功
![](https://img-blog.csdnimg.cn/direct/0faa3ee5bae541f4b43effdcdee56026.png)
三、配置vscode
1、下载如下插件并且启用:
![](https://img-blog.csdnimg.cn/direct/d3b5efee311445498240170d438477bc.png)
![](https://img-blog.csdnimg.cn/direct/4d1b55ae0e9945cdaac72373328d0b40.png)
1、打开配置设置
2、增加配置,保存:
![](https://img-blog.csdnimg.cn/direct/26a58b97b2c8469a88238ba5abcb564f.png)
c
"php.validate.executablePath": "D:\\software\\php\\php-8.3.8-Win32-vs16-x64\\php.exe", //php.exe路径
"php.debug.executablePath": "D:\\software\\php\\php-8.3.8-Win32-vs16-x64\\php.exe", //php.exe路径
"phpserver.browser": "C:/Program Files/Mozilla Firefox/firefox.exe", //浏览器执行文件路径
"phpserver.phpPath": "D:/software/php/php-8.3.8-Win32-vs16-x64/php.exe", //php.exe路径
"phpserver.phpConfigPath": "D:/software/php/php-8.3.8-Win32-vs16-x64/php.ini", //刚才复制配置的配置文件路径
四、代码中使用debug
1、创建一个launch.json 文件
![](https://img-blog.csdnimg.cn/direct/235d9c8bd7d74fbe9f163473e556e312.png)
![](https://img-blog.csdnimg.cn/direct/a7cec9b9fd0549f4b327ff99cdfafe49.png)
![](https://img-blog.csdnimg.cn/direct/d135a363c99e496ca4cf6fe04351dd41.png)
创建成功完成如下: 箭头指的端口号和php,ini的端口号保持一致,如果没有加上。
![](https://img-blog.csdnimg.cn/direct/cd6a8fba230c46d088a12f334ae82302.png)
2、dubug
①打断点,②选择调试模式 ③选择listen for xdebug
3、dubug
1、启动xdebug监听php
![](https://img-blog.csdnimg.cn/direct/3e57eb84cdb246ba8c9013c1cfc6f434.png)
3、启动PHP
![](https://img-blog.csdnimg.cn/direct/5dfe6e4f778f4a9d8d45d0e062afa916.png)