Symfony 4:加载Web调试工具栏时出错



我在 CentOS 上工作。

我遵循了教程:

  • http://symfony.com/doc/current/best_practices/creating-the-project.html

  • https://symfony.com/doc/current/page_creation.html

当我使用Apache时,我也关注了这个页面:

  • https://symfony.com/doc/current/setup/web_server_configuration.html

我制作了一个默认控制器和一个默认模板。使用此控制器 (/),我收到以下错误(在调试工具栏中):

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

当我点击链接:"打开网络分析器"时,我可以看到 Apache 响应:

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

在铬检查器中,我可以看到: 获取 http://172.31.18.7/_wdt/177403 404(未找到)

这是我的作曲家.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"
},

我的 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>

和我的 .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>

最后,我的/lucky/number (https://symfony.com/doc/current/page_creation.html) 会发出 apache 消息:

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

看起来路由组件不起作用。

路由器规则(调试:路由器):

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

为了以防万一,我已经手动创建了目录/_wdt,但它没有改变任何东西。

我已经用debug:event-dispatcher检查了错误,没什么特别的。

我注意到分析器的缓存在该目录中:var/cache/dev/profiler/03/74/,并命名为177403

还有一件事,我已经用"root"用户运行了作曲家。我用chown来改变我的项目的所有者。

这是我的文件.env的一部分:

###> symfony/framework-bundle ###
APP_ENV=dev

我认为这需要 htaccess 或mod_rewrite

composer require symfony/apache-pack
  • 配置 Web 服务器

    https://symfony.com/doc/current/setup/web_server_configuration.html

只需添加:

回退资源/索引.php

在目录设置中

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

有关更多文档,请单击此处

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

主机文件:

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>

如果你使用的是symfonyv5。*
转到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>

如果您需要更多信息,可以访问此处

由于回复在评论中,我重复一遍:

您是否尝试过网址 http://www.elora.dev/index.php/_wdt/?我遇到了类似的问题,因为 URL 重写是错误的。– A.L.(阿·

就是这样!

  1. /index.php 调试工具栏没有任何问题
  2. /index.php/lucky/number works

非常感谢 A.L

Il 听起来像是缓存写入问题。探查器/调试工具栏崩溃,因为调试数据已写入缓存文件夹。您的应用程序可能prod环境中运行良好。

要查看这是否是您的问题,请尝试运行chmod -R 777 var/cache,然后重试。

"更好的修复"取决于您的操作系统。 随意添加更多信息来准确回答,否则您可以在此处查看与Symfony相关的文档(故意过时的链接,他们将其从SF4文档中删除)。

我遇到了同样的错误,这些解决方案没有帮助。就我而言,这是一个简单得多的问题。我将symfony从4.2升级到4.3,但没有将其他软件包(包括Web分析器)升级。哎 呦!在 composer.json 中检查 Web 分析器的版本。

从 4.2 到 4.3 的 Symfony 更新导致 Web 性能分析器中断

有时你可以在控制器中有一个路由来捕获/_wdt/125121,像这样:

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

此处将routed对 Webdebug工具栏的请求,而不是正确的控制器。

使用route requirements或修复路线。

作为对先前答案的一个小补充,如果这种情况发生在一般情况下,而工具栏之前确实有效:

这也可能是由不走运的重命名引起的,人们可能通过全部替换草率地完成了重命名。

在这种情况下,甚至可能只需发出:

bin/console cache:clear

我遇到了错误:

无法访问字符串变量上的属性("nb_errors")

从4.2升级到Symfony解决了我的问题

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

突然收到错误消息的其他可能原因

"加载 Web 调试工具栏时出错。">

  • 您的日志文件太大
  • 您的系统繁忙(如无限循环或达到最大内存等)

在我的案例中,我做了什么以及解决了什么:

  • 重新启动流浪者(当然,如果你在流浪者中运行它)

  • 删除所有日志文件(尤其是您的 dev.log)

    rm -rf var/logs
    
  • 清除缓存

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

这是 Web 调试工具栏通常显示但突然停止显示的时候

最新更新