xdebug 安装,调试

1,首先要获取phpinfo();

2,打开 Xdebug: Support — Tailored Installation Instructions

3,下载该网站推荐的xdebug dll文件

  1. Download php_xdebug-2.9.6-7.3-vc15-nts.dll
  2. Move the downloaded file to D:\PHPCUSTOM\PHPCUSTOM\phpcustom\server\php-7.3.6-nts-x86-web\ext
  3. Edit D:\PHPCUSTOM\PHPCUSTOM\phpcustom\server\php-7.3.6-nts-x86-web\php.ini and add the line
    zend_extension = D:\PHPCUSTOM\PHPCUSTOM\phpcustom\server\php-7.3.6-nts-x86-web\ext\php_xdebug-2.9.6-7.3-vc15-nts.dll

Restart the webserver

如果你下载的是php_xdebug-3.1.6-7.3-vc15-nts-x86_64.dll

无需更多配置

 下载php_xdebug-3.1.6-8.0-vs16-nts-x86_64.dll放在php安装根目录的ext目录,同时配置php.inizend_extension表明安装的扩展模块位置,默认在ext目录寻找,也可以写全物理路径

php.ini

zend_extension=php_xdebug-3.1.6-8.0-vs16-nts-x86_64.dll xdebug.mode = debug xdebug.start_with_request = yes


4,在php.ini里添加xdebug配置文件

本地调试配置

xdebug.auto_trace = 1
xdebug.remote_autostart = 1
;异常跟踪
xdebug.show_exception_trace = 1
;错误跟踪
xdebug.show_error_trace = 0
;错误信息是否强制性显示;默认值: 0,设置为1时,不管PHP设置display_errors设置值是多少,错误信息将强制性一直显示
xdebug.force_display_errors = 1

远程调试配置

zend_extension = D:\PHPCUSTOM\PHPCUSTOM\phpcustom\server\php-7.3.6-nts-x86-web\ext\php_xdebug-2.9.6-7.3-vc15-nts.dll
xdebug.remote_enable = On
xdebug.profiler_enable = On
xdebug.auto_trace=On
xdebug.profiler_enable_trigger = On
xdebug.show_local_vars=0
xdebug.remote_port=9000
xdebug.remote_host="127.0.0.1"
xdebug.remote_log = D:/phpstudy/Extensions/php/log/x-debug-remote.log

 完整配置

[xdebug]
;xdebug库文件
zend_extension = xdebug
;是否允许Xdebug跟踪函数调用,跟踪信息以文件形式存储,默认值为0
xdebug.auto_trace = 1
xdebug.remote_autostart = 1
;异常跟踪
xdebug.show_exception_trace = 1
;错误跟踪
xdebug.show_error_trace = 0
;错误信息是否强制性显示;默认值: 0,设置为1时,不管PHP设置display_errors设置值是多少,错误信息将强制性一直显示
xdebug.force_display_errors = 1

;开启远程调试
xdebug.remote_enable = 1
;客户机ip
xdebug.remote_host = "127.0.0.1"
;客户机xdebug监听端,默认是9000
xdebug.remote_port = 9010
;用于远程调试的应用层通信协议
xdebug.remote_handler = dbgp

;是否开启调试内容
;打开xdebug的性能分析器,以文件形式存储
xdebug.profiler_enable = 1
;性能分析文件的存放位置,默认值为/tmp
xdebug.profiler_output_dir = "C:\MyProgram\wamp64\tmp\xdebug_tmp"
;性能分析文件的命名规则,默认值为cachegrind.out.%p
xdebug.profiler_output_name = cachegrind.out.%p
;函数调用跟踪信息输出文件目录,默认值为/tmp
xdebug.trace_output_dir = "C:\MyProgram\wamp64\tmp\xdebug_tmp"
;函数调用跟踪信息输出文件命名规则,默认为trace.%c
xdebug.trace_output_name = trace.%c

xdebug.cli_color = 1
xdebug.start_with_request = yes
xdebug.idekey = PHPSTORM
;是否允许Xdebug跟踪函数返回值,默认值为0
xdebug.collect_return = 1
;是否允许Xdebug跟踪函数参数,默认值为0
xdebug.collect_params = 1
;是否收集变量
xdebug.collect_vars = 1

xdebug3的配置如下

[xdebug]
zend_extension = "D:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll"
;开启自动跟踪
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.trace_output_dir="D:/phpstudy_pro/Extensions/php_log"
xdebug.profiler_enable=yes
xdebug.profiler_output_dir="D:/phpstudy_pro/Extensions/php_log"
; 调试端口,PhpStorm默认9001
xdebug.client_port = 9001
xdebug.client_host=127.0.0.1
; 记住key,后面需要用到
xdebug.idekey = PHPSTORM

最新xdebug3.0 (验证可用)

[xdebug]
zend_extension="D:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll"
;开启自动跟踪
xdebug.mode = debug
xdebug.start_with_request = yes
; 调试端口,PhpStorm默认9001
xdebug.client_port = 9001
xdebug.client_host=127.0.0.1
; 记住key,后面需要用到
xdebug.idekey = PHPSTORM

 

如果`x-debug-remote.log` 日志出现

[13032] Log opened at 2022-06-20 02:17:36
[13032] I: Connecting to configured address/port: 127.0.0.1:9002.
[13032] I: Connected to client. :-)
[13032] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///D:/phpstudy/WWW/laravel/lararvel7/public/index.php" language="PHP" xdebug:language_version="7.3.2" protocol_version="1.0" appid="13032" idekey="PHPSTORM"><engine version="2.7.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
[13032]
[13032] <- feature_set -i 1 -n show_hidden -v 1
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="show_hidden" success="1"></response>
[13032]
[13032] <- feature_set -i 2 -n max_depth -v 1
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>
[13032]
[13032] <- feature_set -i 3 -n max_children -v 100
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="max_children" success="1"></response>
[13032]
[13032] <- feature_set -i 4 -n extended_properties -v 1
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" feature="extended_properties" success="1"></response>
[13032]
[13032] <- status -i 5
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="status" transaction_id="5" status="starting" reason="ok"></response>
[13032]
[13032] <- step_into -i 6
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="6" status="break" reason="ok"><xdebug:message filename="file:///D:/phpstudy/WWW/laravel/lararvel7/public/index.php" lineno="10"></xdebug:message></response>
[13032]
[13032] <- run -i 7
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="7" status="stopping" reason="ok"></response>
[13032]
[13032] <- stop -i 8
[13032] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="8" status="stopped" reason="ok"></response>

 这样的代码,可能并不是xdebug版本问题,而是单纯的php.ini相关的 xdebug 配置出了问题

5,查看php.ini xdebug 是否已经安装

6,配置phpstorm

自己手动添加一个,Host填服务器ip,然后port是默认80端口,如果你修改过,你可以更改成你设置的web端口,debug选xdebug

测试一下配置是否成功

安装xdebug 谷歌浏览器

7,docker下容器调试xdebug

;如果仅仅是自己测试这个配置就可以啦,不需要dbgp,dbgp是另外链接方式
zend_extension = /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.idekey = "PHPSTORM"
xdebug.remote_enable = 1
xdebug.remote_autostart=1
;宿主机IP
xdebug.remote_host = "192.168.250.185" 
xdebug.remote_port = 9001
xdebug.remote_log = /var/log/x-debug-remote.log




;
zend_extension = /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.idekey = "PHPSTORM"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_mode = "req"
xdebug.remote_host = "192.168.250.185"
xdebug.remote_port = 9001
xdebug.remote_autostart=1
xdebug.show_exception_trace=1
xdebug.remote_log = /var/log/x-debug-remote.log

需要注意的是:

1,remote_host 是宿主机的局域网IP

xdebug.remote_host = "192.168.250.185"

 2,xdebug.remote_log = /var/log/x-debug-remote.log这个很重要 如何没有写入数据,就是权限不够直接上777

如果debug连接不上,查看下 /var/log/x-debug-remote.log,错误提示如下:

[36] Log opened at 2021-08-26 10:00:00
[36] I: Connecting to configured address/port: 192.168.11.202:9001.
[36] E: Time-out connecting to client (Waited: 200 ms). :-(
[36] Log closed at 2021-08-26 10:00:01

可能是xdebug.remote_host = "192.168.250.185" ip改变了 需要重新插看下你的局域网IP

php 7.4.3 版本用法

php.ini  配置文件

zend_extension=D:/phpstudy_pro/Extensions/php/php7.4.3nts/ext/php_xdebug.dll

;开启自动跟踪
xdebug.mode = debug
xdebug.start_with_request = yes
; 调试端口,PhpStorm默认9001
xdebug.client_port = 9005
xdebug.client_host=127.0.0.1
; 记住key,后面需要用到
xdebug.idekey = PHPSTORM

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
您好!要在 VS Code 中使用 Xdebug 进行调试,需要完成以下步骤: 1. 首先,确保您已经在 PHP 环境中安装Xdebug。您可以通过编辑您的 `php.ini` 文件来启用 Xdebug。在 `php.ini` 文件中,找到并取消注释以下行(如果没有则添加): ``` zend_extension = xdebug.so ``` 2. 在 VS Code 中安装 PHP Debug 扩展。打开扩展面板(通过侧边栏的方块图标或者快捷键 `Ctrl+Shift+X`),搜索并安装 "PHP Debug" 扩展。 3. 在 VS Code 中创建一个调试配置文件 `launch.json`。点击 VS Code 左侧的调试图标(虫子图标),然后点击配置齿轮图标以打开 `launch.json` 文件。 4. 在 `launch.json` 文件中,选择 "PHP" 作为环境,并添加一个配置参数,如下所示: ```json { "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 9000, "log": true, "pathMappings": { "/path/to/your/project": "${workspaceFolder}" } } ] } ``` 请将 `/path/to/your/project` 替换为您实际的项目路径。 5. 启动 Xdebug 会话。在 VS Code 中点击调试面板左上角的绿色播放按钮,选择 "Listen for Xdebug" 配置。这将启动 Xdebug 的监听模式。 6. 设置断点。在您的代码中选择要设置断点的行,然后运行您的应用程序。当代码执行到断点时,调试器将会暂停执行并允许您逐步调试。 希望以上步骤能帮助您成功下载并配置 Xdebug 进行调试。如有其他问题,请随时提问!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值