vscode调试php代码(windows)

一、php官网下载你需要的php版本

如:php-7.2.13-Win32-VC15-x86.zip,解压到你需要的路径即可

二、安装并启用xdebug.dll(官网地址

1、Install XDebug,I highly recommend you make a simple test.php file, put a phpinfo(); statement in there, then copy the output and paste it into the XDebug installation wizard. It will analyze it and give you tailored installation instructions for your environment. In short:
On Windows: Download the appropiate precompiled DLL for your PHP version, architecture (64/32 Bit), thread safety (TS/NTS) and Visual Studio compiler version and place it in your PHP extension folder.如:PHP 7.2 VC15 TS (32 bit) 
On Linux: Either download the source code as a tarball or clone it with git, then compile it.
2、Configure PHP to use XDebug by adding zend_extension=path/to/xdebug to your php.ini. The path of your php.ini is shown in your phpinfo() output under "Loaded Configuration File".
3、Enable remote debugging in your php.ini:
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

实际上,直接将该php_xdebug-2.6.1-7.2-vc15.dll放在php根下的zend_ext目录下,然后php.ini中添加以下内容即可:

zend_extension = C:\Program Files\php\zend_ext\php_xdebug-2.6.1-7.2-vc15.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

验证方法:cmd执行命令php -m看是否包含以下的输出内容

[Zend Modules]
Xdebug

三、官网下载安装nginx

解压nginx-1.14.2.zip,并修改conf的网站路径等配置,并启用php-cgi,注意端口号不要跟XDebug端口号一致

四、vscode官网下载并安装vscode编辑器

如:VSCodeSetup-ia32-1.30.0.exe

五、vscode安装PHP IntelliSense和PHP Debug插件

1、ctrl+shift+x或者点击左下角管理中的扩展,输入php,然后安装PHP IntelliSense、PHP Debug插件

2、文件菜单——首选项——设置,然后将"php.validate.executablePath":修改为你的php实际路径

六、调试代码

1、vscode打开你的php程序代码,然后配置调试启动listen for XDebug

launch.json

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}

2、选择php代码,然后单击设置断点,然后F5启动调试,web浏览http://localhost/filename,触发断点

注意:

Xdebug 默认监听的端口是 9000,但 PHP cgi 与 Nginx 通讯的端口一般也是设成 9000 ,两者发生冲突。请修改php-cgi为其他端口

You may also like...

发表评论