Vscode + php + xdebug 单步调试

本文详细介绍了如何在Visual Studio Code(VSCode)中配置Xdebug进行PHP的远程调试,包括修改php.ini设置,安装VSCode的Xdebug插件,创建launch.json文件,设置断点,以及如何通过浏览器和Postman触发调试。确保所有参数如xdebug.remote_enable、remote_host、remote_port和remote_autostart正确设置,并针对多版本PHP选择不同端口。

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等,避免混淆和不生效。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值