symfony - Symfony 3.4:在 prod 环境中启用调试工具栏
问题描述
我正在使用 Symfony 3.4,当我托管我的项目时,我遇到了一个路由问题,所以我必须调试它,但是当我将/app_dev.php添加到我的域名时,我得到一个错误:
You are not allowed to access this file. Check app_dev.php for more information.
Symfony 是否通过简单的配置阻止了 prod 的调试工具?
我尝试了这个解决方案,但它对我不起作用:
https://stackoverflow.com/a/39289662/7041095
我已经完成了所有这些更改,但尚未启用工具栏:
应用程序/AppKernel.php:
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new FOS\UserBundle\FOSUserBundle(),
new MyVendorFOSUserBundle\MyVendorFOSUserBundle(),
];
+ $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
+ $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
+ $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
+
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
应用程序/配置/config.yml:
parameters:
locale: en
+web_profiler:
+ toolbar: true
应用程序/配置/路由.yml:
+
+_wdt:
+ resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
+ prefix: /_wdt
+
+_profiler:
+ resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
+ prefix: /_profiler
+
+_errors:
+ resource: '@TwigBundle/Resources/config/routing/errors.xml'
+ prefix: /_error
网络/app_dev.php:
//commenting this lines:
+
+// if (isset($_SERVER['HTTP_CLIENT_IP'])
+// || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
+// || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
+// ) {
+// header('HTTP/1.0 403 Forbidden');
+// exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
+// }
作曲家.json:
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"friendsofsymfony/user-bundle": "~2.0",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0",
+ "sensio/generator-bundle": "^3.0",
+ "symfony/phpunit-bridge": "^3.0"
},
1) 我死了 ($this->getEnvironement()); => 产品
2) 没有显示工具栏&当我尝试 mydomain/app_dev.php 时出现问题:
ClassNotFoundException
Attempted to load class "SensioGeneratorBundle" from namespace "Sensio\Bundle\GeneratorBundle".
Did you forget a "use" statement for another namespace?
解决方案
如果您在生产中启用了分析器,就像您正在链接的答案一样,那么需要运行应用程序app_dev.php
,app.php
应该可以工作。确保在您composer.json
的列表中,require
而不是requre-dev
如果出于任何原因您必须app_dev.php
在服务器上使用,那么您应该编辑文件并更改它的权限
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
推荐阅读
- docker - .env 文件变量在运行期间不存在:如何检查是否已加载?
- c# - Emgu.CV.Util.CvException: 'OpenCV: i < 0'
- apache-spark - Spark自动触发分区
- python - 如何遍历列表数组,检查每个列表中的元素并与值进行比较,如果它与值匹配则返回键
- javascript -
不适用于新创建的列表项 - python - GTK 无法从条形码扫描仪设备接收键盘输入
- sql-server - 无法在 Powershell 中安装 SQLServer 模块
- java - Hibernate 搜索 - 首先完全匹配
- sql - 从输入的日期时间集中选择日期时间最近的行
- javascript - 为什么所有属性都未定义的对象未列为空?