1、确认xdebug已打开 ( php.ini )
xdebug.remote_enable=1
xdebug.remote_autostart = 1
xdebug.remote_host=localhost
xdebug.remote_port=9000
2、安装 VsCode xDebug插件
![](https://img-blog.csdnimg.cn/4fe131360acc468ea29a9d536a68e40b.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAZHlhbmcxMjk=,size_20,color_FFFFFF,t_70,g_se,x_16)
3、VSCode 配置 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
}
]
}
4、F5 运行监听 9000 端口
![](https://img-blog.csdnimg.cn/f7f2db7c16d1497f9a0a8294d40c4834.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAZHlhbmcxMjk=,size_20,color_FFFFFF,t_70,g_se,x_16)
6、xDebug.php 并添加断点
![](https://img-blog.csdnimg.cn/0b6c9a55bab64fb7a30bf3bd06a10f54.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAZHlhbmcxMjk=,size_20,color_FFFFFF,t_70,g_se,x_16)
7、浏览器打开 test.php 触发调试开始
http://localhost/test/xdebug/xdebug.php
![](https://img-blog.csdnimg.cn/1f37dcf76d0f45748cba6a391f718a5c.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAZHlhbmcxMjk=,size_20,color_FFFFFF,t_70,g_se,x_16)
8、整个项目也是可调试(YII2、Laravel等)
http://example.com
![](https://img-blog.csdnimg.cn/9e112e528d8244cfa075362fd1561e2a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAZHlhbmcxMjk=,size_20,color_FFFFFF,t_70,g_se,x_16)
8、按面的步骤一般没有问题,如果遇到问题要多试几次。正常触发调试以后,使用 postman 同样可以触发调试开启。
9、关键是第一步各项参数设置正确
xdebug.remote_enable=On
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=On
10、多版本PHP, 请为每一个版本设置不同的端口比如: 9056、9073等,避免混淆和不生效。