1,首先要获取phpinfo();
2,打开 Xdebug: Support — Tailored Installation Instructions
3,下载该网站推荐的xdebug dll文件
- Download php_xdebug-2.9.6-7.3-vc15-nts.dll
- Move the downloaded file to D:\PHPCUSTOM\PHPCUSTOM\phpcustom\server\php-7.3.6-nts-x86-web\ext
- Edit
D:\PHPCUSTOM\PHPCUSTOM\phpcustom\server\php-7.3.6-nts-x86-web\php.ini
and add the linezend_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.ini
。zend_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