【问题标题】:Docker Compose - XDebug - VScode Debugging setupDocker Compose - XDebug - VScode 调试设置
【发布时间】:2019-07-19 22:57:26
【问题描述】:

我在使用 VSCode 调试 PHP 时遇到问题。

Dockerfile 暴露端口 80

我要调试的页面真的很简单:

home.php

<?php

$name = 'AAA';
echo $name; <--- here is the breakpoint

php.ini

xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_enable = 1
xdebug.remote_port = 80
xdebug.idekey = VSCODE

launch.json(XDebug 配置)

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9000
    }
  ]
}

调试控制台没有显示任何错误,但是一旦我加载主页,它就不会在断点处停止。

【问题讨论】:

  • "Dockerfile EXPOSE 端口 80" 那又怎样? Xdebug 根本不关心网站端口。 "xdebug.remote_port = 80" 为什么是 80?请先检查 Xdebug 的工作原理以及该值的用途。 xdebug.org/docs/remote#communication

标签: php debugging visual-studio-code docker-compose xdebug


【解决方案1】:

您的设置可能略有不同(因为我在 Laradock 中使用它 - 所以它具有 Laravel 风格)但我相信这些配置应该对您有所帮助。

其中一些设置可能是多余的,但它们是从许多教程中提取的,并且在我的 Localhost 设置中运行良好。

php.ini

xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal  // important if using Mac
xdebug.remote_port=9000                  // important for connection to occur
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_handler=dbgp
xdebug.max_nesting_level=250
xdebug.remote_log=/var/www/xdebug_log/xdebug_docker.log  // for debugging Xdebug!

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

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log": true,
            "pathMappings": {
                "/var/www/app": "${workspaceFolder}/app"  // repoint this
            },
            "xdebugSettings": {
                "max_data": 65535,
                "show_hidden": 1,
                "max_children": 100,
                "max_depth": 5
            }
        }
    ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-23
    • 2021-01-25
    • 2020-06-20
    • 2022-11-11
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多