第一步:Windows环境配置xdebug调试PHP
1.版本对应
php版本,TS 和NTS,VC9和VC11,32位和64位都需要正确才可以。
首先用phpinfo查看PHP安装版本
2.下载对应版本
https://xdebug.org/download.php
比如下载的是32位的TS版本:php_xdebug-2.4.1-5.4-vc9.dll,这个文件复制进任意目录都可以。
3.配置php.ini文件
[Xdebug]
;指定Xdebug扩展文件的绝对路径
zend_extension=D:/WNMP/php/ext/php_xdebug-2.7.0alpha1-7.2-vc15-x86_64.dll
;启用性能检测分析
xdebug.profiler_enable=On
;启用代码自动跟踪
xdebug.auto_trace=on
;允许收集传递给函数的参数变量
xdebug.collect_params=On
;允许收集函数调用的返回值
xdebug.collect_return=On
;指定堆栈跟踪文件的存放目录
xdebug.trace_output_dir="D:/debug"
;指定性能分析文件的存放目录
xdebug.profiler_output_dir="D:/debug"
xdebug.profiler_output_name = "cachegrind.out.%p"
xdebug.remote_enable = On
xdebug.remote_port=9000
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.var_display_max_depth = 10
xdebug.idekey = "PHPSTORM"
4.重启php
查看phpinfo()有无加载好xdebug扩展
说明:如果没有这个说明配置不对或者版本不对
第二步、PHPstorm配置
1、选择PHP版本
2、设置Debug端口号,“Debug port”与“xdebug.remote_port”一致。
3、设置IDEKey
4、设置服务器,在 PHP>Servers 中,将对应服务器的调试工具修改为“Xdebug”,如果没有,请创建。这里的 “Port” 为服务器运行端口
5、增加PHP Web Application。
- 选择Edit Configurations
2. 选择PHP Web Application,增加配置
6、至此,配置基本完成,现在查看一下配置信息。
运行项目目录下的phpinfo.php文件,没有可以自己写一个,查看xdebug.ide,xdebug.remote_port等信息,如下图所示。
7、调试程序。
到这里,就基本完成了phpstorm和xdebug的配置,或许你看这篇文章,第一次配置不会成功。这样的话,建议多搜几篇文章结合看,总是会成功的。