Windows 环境下 PHP 安装 xdebug 及配置

nicelife 2019-12-25

0 引言

目前手动将 PHP 由 7.1.x 升级到 7.2.y 后,VS Code 中的 xdebug 无法使用,用 phpinfo() 查看相关信息,发现 xdebug 插件并未激活——在 phpinfo() 页面看不到 xdebug 的相关信息。

实际上已经在xdebug官网下载了对应版本的dll文件(如下图所示),且在 php.ini 文件中设置了 xdebug 相关dll文件的关联。

Windows 环境下 PHP 安装 xdebug 及配置

[PHP_XDEBUG]
zend_extension = "C:\Program Files\php-7.2.26-nts-Win32-VC15-x64\ext\php_xdebug-2.9.0-7.2-vc15-x86_64.dll"

执行 php.exe 后出现错误提示:

Failed loading C:\Program Files\php-7.2.26-nts-Win32-VC15-x64\ext\php_xdebug-2.9.0-7.2-vc15-x86_64.dll

1 原因

 所加载的 xdebug dll 文件与 PHP 版本不匹配。PHP 是 nts 版本,而不小心下载的 dll 文件是 ts 版本。

TS and NTS

TS refers to multithread capable builds. NTS refers to single thread only builds. Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. For NTS binaries the widespread use case is interaction with a web server through the FastCGI protocol, utilizing no multithreading (but also for example CLI).

 如果不能直接发现此原因,可以将 phpinfo() 页面的文本复制粘贴至 https://xdebug.org/wizard ,并查看页面分析报告,如下图所示。

Windows 环境下 PHP 安装 xdebug 及配置

2 解决方法

下载相应 dll 并按说明配置,重启服务器后,即可在 phpinfo() 页面看到 xdebug 已激活。

Windows 环境下 PHP 安装 xdebug 及配置

相关推荐