29
votes

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
10
Can you check if you closed he body and html tags ?user6830821
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 issueRiggsFolly
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
I've cleared the cache so many times ... I've restarted Apache too. Nothing new.Yves
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

10 Answers

74
votes

I think this is require htaccess or mod_rewrite

composer require symfony/apache-pack
13
votes

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

12
votes
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>
6
votes

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

3
votes

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

3
votes

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
votes

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

0
votes

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.

0
votes

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

0
votes

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