33

I work on CentOS.

I've followed the tutorials :

As I use Apache, I've followed this page too :

I made a default controller and a default template. With this controller (/) I get the the following error (within the debug toolbar):

An error occurred while loading the web debug toolbar. Open the web profiler.

When I click on the link : "Open the web profiler", I can see the Apache response :

Not Found
The requested URL /_profiler/177403 was not found on this server.

In the chrome inspector, I can see : GET http://172.31.18.7/_wdt/177403 404 (Not Found)

Here's the interesting part of my composer.json :

    "require": {
        "php": "^7.1.3",
        "ext-iconv": "*",
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "sensio/framework-extra-bundle": "^5.1",
        "sonata-project/admin-bundle": "^3.35",
        "sonata-project/doctrine-orm-admin-bundle": "^3.6",
        "symfony/apache-pack": "^1.0",
        "symfony/console": "^4.0",
        "symfony/flex": "^1.0",
        "symfony/framework-bundle": "^4.0",
        "symfony/lts": "^4@dev",
        "symfony/maker-bundle": "^1.4",
        "symfony/orm-pack": "^1.0",
        "symfony/requirements-checker": "^1.1",
        "symfony/security-bundle": "^4.0",
        "symfony/twig-bundle": "^4.0",
        "symfony/validator": "^4.0",
        "symfony/yaml": "^4.0"
    },
    "require-dev": {
        "sensiolabs/security-checker": "^4.1",
        "symfony/dotenv": "^4.0",
        "symfony/web-profiler-bundle": "^4.0"
    },

my httpd.conf :

<VirtualHost *:80>
DocumentRoot /var/www/html/elora/public
ServerName eloradev
ServerAlias www.elora.dev
DirectoryIndex index.php

<Directory "elora/public">
    AllowOverride all
    Order Allow,Deny
    Deny from all
    Allow from 127.0.0.1
    Allow from ::1
    Allow from localhost
</Directory>

<Directory elora>
    Options FollowSymlinks
</Directory>    

ErrorLog /var/apache/logs/error.log
CustomLog /var/apache/logs/access.log combined  

</VirtualHost>

And my .htaccess :

DirectoryIndex index.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 307 ^/$ /index.php/
    </IfModule>
</IfModule>

And, to finish, my /lucky/number (https://symfony.com/doc/current/page_creation.html) raises the apache message :

Not Found
The requested URL /lucky/number was not found on this server.

It looks like the routing component does'nt work.

The router rules (debug:router) :

-------------------------- -------- -------- ------ -------------------
Name                       Method   Scheme   Host   Path
-------------------------- -------- -------- ------ ----------------------- 
  app_homepage               ANY      ANY      ANY    /
  app_lucky                  ANY      ANY      ANY    /lucky
  app_lucky_number           ANY      ANY      ANY    /lucky/number
  _twig_error_test           ANY      ANY      ANY    /_error/{code}.{_format}
  _wdt                       ANY      ANY      ANY    /_wdt/{token}
  _profiler_home             ANY      ANY      ANY    /_profiler/
  _profiler_search           ANY      ANY      ANY    /_profiler/search
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open
  _profiler                  ANY      ANY      ANY    /_profiler/{token}
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css
 -------------------------- -------- -------- ------ -----------------------

I've manually created the directory /_wdt, in case, but it did'nt change anything.

I've checked errors with debug:event-dispatcher, nothing special.

I've noticed that the cache for the profiler is in that directory : var/cache/dev/profiler/03/74/ and is named 177403

One more thing, I've ran composer with the 'root' user. And I've used chown to change the owner of my project.

Here's a part of my file .env :

###> symfony/framework-bundle ###
APP_ENV=dev
8
  • Can you check if you closed he body and html tags ?
    – user6830821
    Commented Apr 27, 2018 at 9:56
  • 1
    I see this now and again. To fix it I delete everything under var\cache and \var\session restart Apache and then warmup the cache again, or just run the site and let the cache get rebuilt. Takes a minute longer but solves the issue
    – RiggsFolly
    Commented Apr 27, 2018 at 9:57
  • I didn't do any change to base.html.twig, so the tags are OK. I've forgot to say that I made a default controller and a default template. That's how I got the message "An error occurred while loading the web debug toolbar"
    – Yves
    Commented Apr 27, 2018 at 10:00
  • I've cleared the cache so many times ... I've restarted Apache too. Nothing new.
    – Yves
    Commented Apr 27, 2018 at 10:11
  • 1
    Did you try the URL http://www.elora.dev/index.php/_wdt/ ? I had a similar problem because the URL rewriting was wrong. Commented Apr 27, 2018 at 11:59

11 Answers 11

81

I think this is require htaccess or mod_rewrite

composer require symfony/apache-pack
3
  • Thanks this solved the issue for me running the symfony app in a vagrant box for development. Commented Jul 20, 2018 at 9:04
  • In my case i wanted to work with or without an .htaccess file, so ended up with a different vhost configuration, for more information: ourcodeworld.com/articles/read/793/… Commented Aug 14, 2018 at 18:27
  • @DennisdeBest Unfortunately this didn't work running a symfony app in a laravel homestead :/
    – Pathros
    Commented Nov 13, 2020 at 19:21
14
composer require symfony/apache-pack

Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n): y

Host File:

127.0.0.1 symfony01.com
127.0.0.1 www.symfony01.com

httpd-vhosts.conf :

<VirtualHost *:80>
    ServerName symfony01.com
    ServerAlias www.symfony01.com   
    DocumentRoot "c:/wamp64/www/symfony01/public"
    <Directory  "c:/wamp64/www/symfony01/public/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
1
  • 2
    Thanks! I forgot about apache-pack Commented Apr 4, 2020 at 18:04
13

just add :

FallbackResource /index.php

in your directory setting

    <Directory "/Library/WebServer/Documents/Your_public_symfony_directory">
            ....
            FallbackResource /index.php
            ....
    </Directory>

for more documentation click here

1
  • Thank you, this worked with Laragon (Apache 2.4 + PHP 7.2). Commented Jul 21, 2019 at 4:58
10

If you are using symfony v5.*
go to your_project_root > public create a new file named .htaccess Just paste the code:


DirectoryIndex index.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 307 ^/$ /index.php/
    </IfModule>
</IfModule>

if you need more information you can visit here

2
  • I was working on a Symfony 5.* project myself and being new to the framework Your answer definitely helped. Commented Dec 10, 2020 at 23:30
  • An error occurred while loading the web debug toolbar. Commented Feb 25, 2022 at 9:09
6

As the response is in a comment, i repeat it :

Did you try the URL http://www.elora.dev/index.php/_wdt/ ? I had a similar problem because the URL rewriting was wrong. – A.L

That's it !

  1. /index.php doesn't have any issue with the debug toolbar
  2. /index.php/lucky/number works

Thank's a lot A.L

4

Il sounds like a cache write issue. The profiler/debug toolbar crash because debug data is written to cache folder. Your application is probably running fine in prod environment.

To see if that's your issue, try running chmod -R 777 var/cache, and try again.

The "better fix" depend on your OS. Feel free to add some more information to answer precisely, otherwise you can have a look at Symfony related documentation here (outdated link on purpose, they removed it from SF4 doc).

2
  • Thank you for the answer, but i've already done the chmod 777 on var/cache, and the setfacl didn't change anything. My application runs in dev environment.
    – Yves
    Commented Apr 27, 2018 at 11:39
  • As I said, I've noticed that the cache for the profiler is in that directory : var/cache/dev/profiler/03/74/ and is named 177403 So there's not any cache write issue.
    – Yves
    Commented Apr 27, 2018 at 11:45
2

I had the same error and these solutions didn't help. In my case it was a much simpler problem. I upgraded symfony from 4.2 to 4.3, but not the other packages (including the web profiler). Whoops! Check the version of web profiler in composer.json.

Symfony update from 4.2 to 4.3 caused Web Profiler to break

1

Sometimes you can have a route in your controllers that catches /_wdt/125121, something like this:

@Route("/{_locale}/{courseSlug}", name="learning_course")

The requests for web debug toolbar will be routed here instead of the correct controller.

Use route requirements or fix your routes.

1

As a small addition to previous answers if this happens to someone in general while the toolbar did indeed work before:

this can also be caused by unlucky renamings that one might have sloppily done via a replace all.

In this case it might even be sufficient to just issue:

bin/console cache:clear
1
  • Then you probably got something else going on as well. Did you check the possible causes from previous answers as well? Furthermore, you might wanna cache-bust your browser as "hard" as possible.
    – Wolfone
    Commented Nov 17, 2020 at 7:32
1

Other possible reasons of suddenly getting the error message

"An error occurred while loading the web debug toolbar."

  • Your log files got too big
  • Your system is busy (like an endless loop or max memory was reached etc.)

What I did and what resolved it in my case:

  • Restart vagrant (if you are running it in vagrant of course)

  • Delete all the log files (especially your dev.log)

    rm -rf var/logs
    
  • Clear the cache

    bin/console cache:clear
    
    # OR if cache got corrupted
    rm -rf var/cache
    

This is when the web debug toolbar usually showed but suddenly stopped showing

0

I had the error:

Impossible to access an attribute ("nb_errors") on a string variable

Upgrading to Symfony from 4.2 to 4.3 solved my problem

see https://github.com/symfony/symfony/issues/32018

2
  • How is this related to the given question? Looks like a completely different error
    – Nico Haase
    Commented Oct 28, 2020 at 13:58
  • 1
    the error I pointed, when solved, make the error "An error occurred while loading the web debug toolbar" disappeared
    – Gautier
    Commented Oct 28, 2020 at 14:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.