[英]Symfony 4 : An error occurred while loading the web debug toolbar
I work on CentOS.我在 CentOS 上工作。
I've followed the tutorials :我已经按照教程:
http://symfony.com/doc/current/best_practices/creating-the-project.html http://symfony.com/doc/current/best_practices/creating-the-project.html
https://symfony.com/doc/current/page_creation.html https://symfony.com/doc/current/page_creation.html
As I use Apache, I've followed this page too :当我使用 Apache 时,我也关注了这个页面:
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 :当我点击链接:“打开网络分析器”时,我可以看到 Apache 响应:
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)在 chrome 检查器中,我可以看到:GET http://172.31.18.7/_wdt/177403 404(未找到)
Here's the interesting part of my composer.json :这是我的 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 :我的 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 :还有我的 .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 :最后,我的 /lucky/number ( https://symfony.com/doc/current/page_creation.html ) 引发了 apache 消息:
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.我手动创建了目录 /_wdt,以防万一,但它没有改变任何东西。
I've checked errors with debug:event-dispatcher, nothing special.我已经用 debug:event-dispatcher 检查过错误,没什么特别的。
I've noticed that the cache for the profiler is in that directory : var/cache/dev/profiler/03/74/ and is named 177403我注意到分析器的缓存位于该目录中:var/cache/dev/profiler/03/74/ 并命名为 177403
One more thing, I've ran composer with the 'root' user.还有一件事,我用“root”用户运行作曲家。 And I've used chown to change the owner of my project.
我已经使用 chown 更改了我的项目的所有者。
Here's a part of my file .env :这是我的文件 .env 的一部分:
###> symfony/framework-bundle ###
APP_ENV=dev
I think this is require htaccess or mod_rewrite我认为这是需要 htaccess 或 mod_rewrite
composer require symfony/apache-pack
Configuring a Web Server配置 Web 服务器
https://symfony.com/doc/current/setup/web_server_configuration.html https://symfony.com/doc/current/setup/web_server_configuration.html
just add :只需添加:
FallbackResource /index.php回退资源/index.php
in your directory setting在您的目录设置中
<Directory "/Library/WebServer/Documents/Your_public_symfony_directory"> .... FallbackResource /index.php .... </Directory>
for more documentation click here有关更多文档, 请单击此处
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 : 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>
As the response is in a comment, i repeat it :由于回复在评论中,我重复一遍:
Did you try the URL http://www.elora.dev/index.php/_wdt/ ?您是否尝试过 URL http://www.elora.dev/index.php/_wdt/ ? I had a similar problem because the URL rewriting was wrong.
我有一个类似的问题,因为 URL 重写是错误的。 – AL
– AL
That's it !就是这样 !
Il sounds like a cache write issue. Il 听起来像是缓存写入问题。 The profiler/debug toolbar crash because debug data is written to cache folder.
探查器/调试工具栏崩溃,因为调试数据被写入缓存文件夹。 Your application is probably running fine in
prod
environment.您的应用程序可能在
prod
环境中运行良好。
To see if that's your issue, try running chmod -R 777 var/cache
, and try again.要查看这是否是您的问题,请尝试运行
chmod -R 777 var/cache
,然后重试。
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).
随意添加更多信息以准确回答,否则您可以在此处查看 Symfony 相关文档(故意过时的链接,他们将其从 SF4 文档中删除)。
If you are using symfony v5.如果您使用的是 symfony v5。 *
*
go to your_project_root > public
create a new file named .htaccess
Just paste the code:转到
your_project_root > public
创建一个名为.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>
if you need more information you can visit here如果您需要更多信息,您可以访问这里
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).
我将 symfony 从 4.2 升级到 4.3,但没有将其他软件包(包括 Web Profiler)升级。 Whoops!
哎呀! Check the version of web profiler in composer.json.
在 composer.json 中检查 Web Profiler 的版本。
Symfony update from 4.2 to 4.3 caused Web Profiler to break Symfony 从 4.2 更新到 4.3 导致 Web Profiler 崩溃
Sometimes you can have a route in your controllers that catches /_wdt/125121
, something like this:有时,您的控制器中可以有一条路由来捕获
/_wdt/125121
,如下所示:
@Route("/{_locale}/{courseSlug}", name="learning_course")
The requests for web debug
toolbar will be routed
here instead of the correct controller. Web
debug
工具栏的请求将被routed
到这里而不是正确的控制器。
Use route requirements
or fix your routes.使用
route requirements
或修复您的路线。
I had the error:我有错误:
Impossible to access an attribute ("nb_errors") on a string variable
无法访问字符串变量的属性(“nb_errors”)
Upgrading to Symfony from 4.2 to 4.3 solved my problem从 4.2 升级到 Symfony 到 4.3 解决了我的问题
see https://github.com/symfony/symfony/issues/32018见https://github.com/symfony/symfony/issues/32018
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
Other possible reasons of suddenly getting the error message突然收到错误信息的其他可能原因
"An error occurred while loading the web debug toolbar."
“加载 Web 调试工具栏时出错。”
What I did and what resolved it in my case:我做了什么以及在我的情况下解决了什么:
Restart vagrant (if you are running it in vagrant of course)重新启动 vagrant(当然,如果您在 vagrant 中运行它)
Delete all the log files (especially your dev.log)删除所有日志文件(尤其是你的 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这是 Web 调试工具栏通常显示但突然停止显示的时间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.