【问题标题】:Symfony 5.x - An error occurred while loading the web debug toolbarSymfony 5.x - 加载 Web 调试工具栏时出错
【发布时间】:2020-11-08 08:23:04
【问题描述】:

我正在使用 Symfony 5.X,它是在 docker 上的全新安装,带有图像“bitnami/symfony”。 我也使用“bitnami/nginx”和“bitnami/php-fpm”。除了 Web Profiler 工具栏外,所有功能都很好。

我过去 2 天在 Google 上寻找解决方案,但没有任何效果。 我可以访问 url /_profiler/ 但是如果我点击一个令牌来查看一些详细信息,我会收到一个错误 500。

TypeError:
Argument 5 passed to Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer::__construct() must be a string or a callable, Symfony\Component\HttpFoundation\RequestStack given.

  at /app/simtp/vendor/symfony/error-handler/ErrorRenderer/HtmlErrorRenderer.php:53
  at Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer->__construct(true, 'UTF-8', object(FileLinkFormatter), '/app/simtp', object(RequestStack), object(Logger))
     (/app/simtp/var/cache/dev/ContainerIRQxaSE/App_KernelDevDebugContainer.php:2035)
  at ContainerIRQxaSE\App_KernelDevDebugContainer->getErrorHandler_ErrorRenderer_HtmlService()
     (/app/simtp/var/cache/dev/ContainerIRQxaSE/App_KernelDevDebugContainer.php:719)
  at ContainerIRQxaSE\App_KernelDevDebugContainer->getErrorControllerService()
     (/app/simtp/vendor/symfony/dependency-injection/Container.php:242)
  at Symfony\Component\DependencyInjection\Container->make('error_controller', 1)
     (/app/simtp/vendor/symfony/dependency-injection/Container.php:222)
  at Symfony\Component\DependencyInjection\Container->get('error_controller')
     (/app/simtp/vendor/symfony/http-kernel/Controller/ContainerControllerResolver.php:53)
  at Symfony\Component\HttpKernel\Controller\ContainerControllerResolver->instantiateController('error_controller')
     (/app/simtp/vendor/symfony/framework-bundle/Controller/ControllerResolver.php:29)
  at Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver->instantiateController('error_controller')
     (/app/simtp/vendor/symfony/http-kernel/Controller/ControllerResolver.php:108)
  at Symfony\Component\HttpKernel\Controller\ControllerResolver->createController('error_controller')
     (/app/simtp/vendor/symfony/http-kernel/Controller/ContainerControllerResolver.php:42)
  at Symfony\Component\HttpKernel\Controller\ContainerControllerResolver->createController('error_controller')
     (/app/simtp/vendor/symfony/http-kernel/Controller/ControllerResolver.php:86)
  at Symfony\Component\HttpKernel\Controller\ControllerResolver->getController(object(Request))
     (/app/simtp/vendor/symfony/http-kernel/Controller/TraceableControllerResolver.php:38)
  at Symfony\Component\HttpKernel\Controller\TraceableControllerResolver->getController(object(Request))
     (/app/simtp/vendor/symfony/http-kernel/HttpKernel.php:128)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 2)
     (/app/simtp/vendor/symfony/http-kernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 2, false)
     (/app/simtp/vendor/symfony/http-kernel/EventListener/ErrorListener.php:60)
  at Symfony\Component\HttpKernel\EventListener\ErrorListener->onKernelException(object(ExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
     (/app/simtp/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(ExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
     (/app/simtp/vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(ExceptionEvent))
     (/app/simtp/vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(ExceptionEvent), 'kernel.exception')
     (/app/simtp/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(ExceptionEvent), 'kernel.exception')
     (/app/simtp/vendor/symfony/http-kernel/HttpKernel.php:206)
  at Symfony\Component\HttpKernel\HttpKernel->handleThrowable(object(TypeError), object(Request), 1)
     (/app/simtp/vendor/symfony/http-kernel/HttpKernel.php:99)
  at Symfony\Component\HttpKernel\HttpKernel->terminateWithException(object(TypeError), object(Request))
     (/app/simtp/vendor/symfony/http-kernel/EventListener/DebugHandlersListener.php:114)
  at Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::Symfony\Component\HttpKernel\EventListener\{closure}(object(TypeError))
     (/app/simtp/vendor/symfony/error-handler/ErrorHandler.php:592)
  at Symfony\Component\ErrorHandler\ErrorHandler->handleException(object(TypeError))

我认为正是由于这个原因,我的工具栏显示“加载网络调试工具栏时发生错误”。

这是我为这个网站设置的 Nginx 配置文件:

server {
    server_name simtp.local www.simtp.local;
    root /app/simtp/public;
    listen 0.0.0.0:8080;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
        #try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # optionally disable falling back to PHP script for the asset directories;
    # nginx will return a 404 error when files are not found instead of passing the
    # request to Symfony (improves performance but Symfony's 404 page is not displayed)
    # location /bundles {
    #     try_files $uri =404;
    # }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass phpfpm:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;

        # optionally set the value of the environment variables used in the application
        # fastcgi_param APP_ENV prod;
        # fastcgi_param APP_SECRET <app-secret-id>;
        # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $document_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/index.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
        return 404;
    }

    #error_log /opt/bitnami/nginx/project_error.log;
    #access_log /opt/bitnami/nginx/project_access.log;
}

我的 docker-compose 文件:

version: '2'

services:
  nginx:
    image: 'bitnami/nginx:1.16'
    ports:
      - '8784:8080'
    networks:
      - default
    depends_on:
      - phpfpm
    volumes:
      - './simtp/public/simtp.conf:/opt/bitnami/nginx/conf/server_blocks/simtp.conf:ro'
  phpfpm:
    image: 'bitnami/php-fpm:latest'
    networks:
      - default
    volumes:
      - './simtp:/app/simtp'
  simtp:
    image: 'bitnami/symfony:1'
    ports:
      - '8780:8000'
    volumes:
      - '.:/app'
    environment:
      - TZ=America/New_York
      - SYMFONY_PROJECT_NAME=simtp
    depends_on:
      - simtp_api
      - nginx
    networks:
      - default
  simtp_api:
    image: 'bitnami/symfony:1'
    ports:
      - '8782:8000'
    volumes:
      - '.:/app'
    environment:
      - TZ=America/New_York
      - SYMFONY_PROJECT_NAME=simtp_api
      - MYSQL_ROOT_USER=root
      - MYSQL_ROOT_PASSWORD=
      - MYSQL_USER=simtp01
      - MYSQL_PASSWORD=***************
      - MYSQL_DATABASE=simtp
      - ALLOW_EMPTY_PASSWORD=yes
    depends_on:
      - mysqldb
      - nginx
    networks:
      default:
        aliases:
          - api.simtp.local
  mysqldb:
  ...
  ...
  ...

我在论坛上看到有人用 symfony/apache-pack 包解决了这个问题,但我不想使用 Apache,因为我已经有 Nginx。

我没有更多的想法,我已经尝试了很多东西,如果有人可以帮助我,那就太好了。

【问题讨论】:

  • 你有完整的堆栈跟踪吗?这个错误具体发生在哪里?从错误消息来看,我不会认为这是您的 nginx/docker-compose 设置的问题,而是 php 代码中的错误,无论是 Symfony 还是您的。
  • 当我转到 url /_profiler 时发生错误(当我单击令牌时),例如 /_profiler/3bba77。我刚刚编辑了我的帖子以添加堆栈跟踪。我想指定我的项目是全新安装的,我的控制器只呈现一个测试视图(使用 make:controller 启动的控制器)。视图包含所有最小代码(html、body 等)

标签: php symfony nginx


【解决方案1】:

这是 Symfony 5.0.0 中的一个错误,应该已经在 5.0.1 中修复。您可以看到配置更改,这可能会在此处解决此问题:https://github.com/symfony/symfony/compare/v5.0.0...v5.0.1#diff-414443648aa78565f2158b8154a1ff8e

最好的方法是运行composer update

【讨论】:

  • 我刚刚在他们的 Github 上的帖子中看到了这一点,也感谢您的宝贵时间!升级到 5.0.1 是有效的解决方案!
【解决方案2】:

将 Symfony 5.0.0 更新到 5.0.1 对我不起作用,因为我已经在 5.0.1 中了。解决方案更简单,只需从 Symfony 项目中删除 var/cache 文件夹即可使工具栏再次工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-30
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    相关资源
    最近更新 更多