PHPStudy_Pro 8.1.1.2
VsCode 1.51.1
PHP 7.4.3 NTS
PHP_Xdebug-2.9.8-7.4-vc15-nts-x86_64

首先查看当前环境的phpinfo信息

VsCode配置PHP断点调试环境笔记_PHP


根据phpinfo的信息选择对应的XDebug进行下载:https://xdebug.org/download

推荐使用:https://xdebug.org/wizard,将phpinfo的信息全选复制到这里进行分析,然后下载这里推荐的XDebug版本

VsCode配置PHP断点调试环境笔记_json_02


VsCode配置PHP断点调试环境笔记_PHP_03


将下载好的php_xdebug-2.9.8-7.4-vc15-nts-x86_64.dll放入PHP环境的ext目录下

VsCode配置PHP断点调试环境笔记_PHP_04


并在当前PHP环境的php.ini中添加[xdebug]的配置项

VsCode配置PHP断点调试环境笔记_php_05

[xdebug]
zend_extension=D:\phpstudy_pro\Extensions\php\php7.4.3nts\ext\php_xdebug-2.9.8-7.4-vc15-nts-x86_64.dll
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.idekey="VSCODE"
xdebug.remote_log="D:/phpstudy_pro/Extensions/php/php7.4.3nts/xdebug.log"

检查PHPStudy_Pro的当前PHP版本是否开启XDebug调试,以及PHP扩展是否开启XDebug

VsCode配置PHP断点调试环境笔记_json_06


VsCode配置PHP断点调试环境笔记_PHP_07


重启PHP环境,查看phpinfo中是否有xdebug模块信息,以及配置的项是否正确

VsCode配置PHP断点调试环境笔记_PHP_08

VsCode配置PHP断点调试环境笔记_php_09


打开VsCode安装扩展PHP DebugPHP IntelliSense

VsCode配置PHP断点调试环境笔记_php_10


Ctrl+p搜索settings.json,添加

"php.validate.executablePath": "D:/phpstudy_pro/Extensions/php/php7.4.3nts/php.exe"

创建个文件夹,在该文件夹下创建个php文件,配置该文件夹下./vscode/launch.json文件

VsCode配置PHP断点调试环境笔记_php_11


端口注意与xdebug.remote_port一致

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: 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
        }
    ]
}

VsCode配置PHP断点调试环境笔记_php_12


查看是否监听9000端口

netstat -ano | findstr '9000'

VsCode配置PHP断点调试环境笔记_php_13