Laravel + Mac + Vscode + Laradock 配置 Xdebug

Laravel框架
452
0
0
2022-07-27
标签   VSCode
搞了一小时才配置成功,中间有些操作怕回头记不清了,在这里记录一下。

配置laradock.env文件配置php-fpm安装xdebug依赖;

...
PHP_FPM_INSTALL_XDEBUG=true
...

配置php-fpmxdebug配置文件/laradock/php-fpm/xdebug.ini

## 如果是 win 则是 docker.for.win.localhost
## 也可以配置成 host.docker.internal 我在 mac 下测试也可以 win 没测试
xdebug.remote_host=docker.for.mac.localhost 

xdebug.remote_connect_back=0
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM

xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.cli_color=0
xdebug.profiler_enable=0
xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"

xdebug.remote_handler=dbgp
xdebug.remote_mode=req

xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1

重新构建laradock php-fpm

$  docker-compose up -d  --build php-fpm

配置项目在vscode下的launch.json文件;

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log": true,
            "pathMappings": {
                "/var/www/项目在 workspace 下的绝对地址": "${workspaceRoot}",
            }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

然后就可以愉快的debug了。