php Symfony 4:加载 Web 调试工具栏时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50059794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony 4 : An error occurred while loading the web debug toolbar
提问by Yves
I work on CentOS.
我在 CentOS 上工作。
I've followed the tutorials :
我已经按照教程:
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/177403404 (Not Found)
在 chrome 检查器中,我可以看到:GET http://172.31.18.7/_wdt/177403404(未找到)
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}:: ^(/.+)/(.*)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/ [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. And I've used chown to change the owner of my project.
还有一件事,我用“root”用户运行作曲家。我已经使用 chown 更改了我的项目的所有者。
Here's a part of my file .env :
这是我的文件 .env 的一部分:
###> symfony/framework-bundle ###
APP_ENV=dev
回答by MooMoo Cha
I think this is require htaccess or mod_rewrite
我认为这是需要 htaccess 或 mod_rewrite
composer require symfony/apache-pack
Configuring a Web Server
https://symfony.com/doc/current/setup/web_server_configuration.html
回答by rapaelec
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
有关更多文档,请单击此处
回答by Ak?n K?ker
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>
回答by Yves
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
您是否尝试过 URL http://www.elora.dev/index.php/_wdt/?我有一个类似的问题,因为 URL 重写是错误的。– AL
That's it !
就是这样 !
- /index.php doesn't have any issue with the debug toolbar
- /index.php/lucky/number works
- /index.php 调试工具栏没有任何问题
- /index.php/lucky/number 有效
Thank's a lot A.L
非常感谢AL
回答by romaricdrigon
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.
Il 听起来像是缓存写入问题。探查器/调试工具栏崩溃,因为调试数据被写入缓存文件夹。您的应用程序可能在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 文档中删除)。
回答by hipnosis
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 从 4.2 升级到 4.3,但没有将其他软件包(包括 Web Profiler)升级。哎呀!在 composer.json 中检查 Web Profiler 的版本。
回答by Sergiu
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.
对 Webdebug
工具栏的请求将在routed
此处而不是正确的控制器。
Use route requirements
or fix your routes.
使用route requirements
或修复您的路线。