vscode进行php@7.0的调试xdebug

140 阅读1分钟

1、安装xdebug的扩展,xdebug版本在xdebug.org官网中查找xdebug.org/download/hi…

sudo pecl install xdebug-2.7.0

2、执行php -v查看是否安装成功

image.png

3、执行php --ini 配置php.ini

image.png

添加如下信息 [xdebug] zend_extension="/opt/homebrew/Cellar/php@7.0/7.0.33_6/pecl/20151012/xdebug.so" xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_port = 9003 xdebug.start_with_request=yes

4、vscode安装插件

image.png

php Debug

php intelephense 语法提示

php extension pack 拓展包

5、创建launch.json文件

{
    // 使用 IntelliSense 了解相关属性。
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}

6、设置settings.json

"php.executablePath": "/opt/homebrew/Cellar/php@7.0/7.0.33_6",
"php.debug.executablePath": "/opt/homebrew/Cellar/php@7.0/7.0.33_6",