1、确认xdebug已打开 ( php.ini )
xdebug.remote_enable=1
xdebug.remote_autostart = 1
xdebug.remote_host=localhost
xdebug.remote_port=9000
2、安装 VsCode xDebug插件
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 端口
6、xDebug.php 并添加断点
7、浏览器打开 test.php 触发调试开始
http://localhost/test/xdebug/xdebug.php
8、整个项目也是可调试(YII2、Laravel等)
http://example.com
8、按面的步骤一般没有问题,如果遇到问题要多试几次。正常触发调试以后,使用 postman 同样可以触发调试开启。
9、关键是第一步各项参数设置正确
xdebug.remote_enable=On
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=On
10、多版本PHP, 请为每一个版本设置不同的端口比如: 9056、9073等,避免混淆和不生效。