Laravel + Mac + Vscode + Laradock 配置 Xdebug

搞了一小时才配置成功,中间有些操作怕回头记不清了,在这里记录一下。

配置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了。

本作品采用《CC 协议》,转载必须注明作者和本文链接
Life emerges from calamity and sorrow, but death comes from the joyful state of oblivion.
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!