在vscode中使用xdebug调试PHP---绝对解决远程xdebug调试不了的问题

在vscode中使用xdebug调试PHP—绝对解决远程xdebug调试不了的问题

1.vscode插件安装

在这里插入图片描述

2.检查并安装php的xdebug扩展

php -m

在这里插入图片描述

3.修改远程主机上php.ini中的xdebug的配置信息

vi php.ini

在这里插入图片描述

4.修改vscode中的launch.json文件

{
    
    
    // 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": "Launch built-in server and debug",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-S",
                "localhost:8000",
                "-t",
                "."
            ],
            "port": 9003,
            "serverReadyAction": {
    
    
                "action": "openExternally"
            }
        },
        {
    
    
            "name": "Debug current script in console",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "port": 9003
        },
        {
    
    
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",    
            "port": 9003,
            "pathMappings": {
    
    "/com/web": "${workspaceFolder}/aaa"}
        }
    ]
}

说明:

  • ”port”是本地IDE在debug时会监听的端口,远程xdebug与vscode通信时就是使用这个端口。这个端口要必须与php.ini配置的xdebug的配置的端口一样

重点:
有时候,远程debug会遇到明明xdebug的好的,但是调试始终进不来断点,那么一定要配置pathMappings,具体的配置如示例,就可以了

说明:

  • 本地代码目录结构
 tree
 
 结果:
├── .vscode
    ├── launch.json
├── aaa
	├── composer.json
	├── composer.lock
	├── Dockerfile
	├── README.md
	├── src
	│   ├── Controllers
	│   ├── Global
	│   ├── Models
	│   ├── module
	│   ├── resource.ini
	│   └── Utils
	├── vendor

远程环境的代码路径:

├── com
	├── web
		├── composer.json
		├── composer.lock
		├── Dockerfile
		├── README.md
		├── src
		│   ├── Controllers
		│   ├── Global
		│   ├── Models
		│   ├── module
		│   ├── resource.ini
		│   └── Utils
		├── vendor

猜你喜欢

转载自blog.csdn.net/sunrj_niu/article/details/130106604
今日推荐