Docker + Visual Studio Code IDE实现PHP Xdebug调试

一、前期准备

1、安装 VSCode 软件;

2、在 VSCode 中安装 PHP Debug 插件;

3、安装好 Docker

4、在容器中 php 中安装安装 Xdebug 扩展

根据这个链接操作即可: Xdebug安装指南
把php环境的 phpinfo()全部copy进去,会自动获得xdebug的安装文件以及安装指导!

具体参考下面的文档

https://www.cnblogs.com/itsharehome/p/11462587.html

二、配置文件

1. Visual Studio Code IDE配置

配置vs_code里的 PHP Debuglaunch.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": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            // "hostname": "192.168.1.8",
            "port": 9001,  //要和php.ini中的xdebug.remote_port一致
            "pathMappings": {
                //宿主主机项目根目录:容器内的项目根目录 不用写到public目录
                "/www/youtaikeji/ytss_server":"/Users/youtai/code/wwwroot/youtaikeji/ytss_server"
            }
        }
    ]
}

2、配置 dockerphpxdebug.ini

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = "dbgp"
; Set to host.docker.internal on Mac and Windows, otherwise, set to host real ip
; xdebug.remote_host = host.docker.internal
xdebug.remote_host = 192.168.2.47 # 宿主机的ip地址
; 监听的端口,vs_code编辑器中启动xdebug时,也要写这个端口,不建议设置9000,避免与php-fpm监听端口冲突
xdebug.remote_port = 9001 
xdebug.remote_log = /var/log/php/xdebug2.log

SERVER_ENV=develop

yaf.use_spl_autoload=1

注意:配置完成后需要重启对应docker容器,为避免配置失效,请使用docker commit命令提交保存镜像修改。

三、开始调试

1、vscode中按F5,开启调试模式

2、请求docker路径...

参考文档

posted @ 2024-06-21 09:41  HaimaBlog  阅读(63)  评论(0编辑  收藏  举报