Skip to content
Advertisement

Symfony 5.x – An error occurred while loading the web debug toolbar

I’m working with Symfony 5.X, it’s a fresh install on docker with the image “bitnami/symfony”. I use too “bitnami/nginx” and “bitnami/php-fpm”. All work good except the web profiler toolbar.

I passed the 2 last days on Google searching for a solution but nothing work. I can access the url /_profiler/ but if I click on a token to view some details I get an error 500.

TypeError:
Argument 5 passed to SymfonyComponentErrorHandlerErrorRendererHtmlErrorRenderer::__construct() must be a string or a callable, SymfonyComponentHttpFoundationRequestStack given.

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

I think it’s for this reason that my toolbar is showing “An error occurred while loading the web debug toolbar“.

Here is my Nginx conf for this site:

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;
}

My docker-compose file:

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:
  ...
  ...
  ...

I read on forums that some people fix this problem with the package symfony/apache-pack but I don’t want to use Apache because I have already Nginx.

I have no more idea, I have tried so much things, if someone can help me it will be nice.

Advertisement

Answer

This is a bug in Symfony 5.0.0 that should already be fixed in 5.0.1. You can see the configuration change, that probably will fix this here: https://github.com/symfony/symfony/compare/v5.0.0…v5.0.1#diff-414443648aa78565f2158b8154a1ff8e

The best approach would be to run composer update

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement