Symfony将dev更改为prod



我有以下问题,我把symfony放在服务器上,我在app_dev.php调试中将其更改为false,在app.php中更改为true,现在我应该在信息php-bin/console中获取我有一个prod的设置版本的信息,为什么dev一直向我显示?当然,调试栏不会出现,在进入url app_dev.php_profiler后,我会得到一个错误

Error: Can not redeclare class SymfonyComponentDebugErrorHandler

然而,在输入example.com/_profiler后,我得到了错误:

No route found for "GET /_profiler"

php bin/console关于结果,当我将dev更改为false时,将prod更改为true

Symfony
-------------------- ---------------------------------
Version              3.4.8
End of maintenance   11/2020
End of life          11/2021
-------------------- ---------------------------------
Kernel
-------------------- ---------------------------------
Type                 AppKernel
Name                 app
Environment          dev
Debug                true
Charset              UTF-8
Root directory       ./app
Cache directory      ./var/cache/dev (3.0 MiB)
Log directory        ./var/logs (32.0 MiB)
-------------------- ---------------------------------
PHP
-------------------- ---------------------------------
Version              5.6.33-0+deb8u1
Architecture         64 bits
Intl locale          pl_PL
Timezone             UTC (2018-10-07T09:30:23+00:00)
OPcache              true
APCu                 false
Xdebug               false
-------------------- ---------------------------------

我的app.php

<?php
use SymfonyComponentHttpFoundationRequest;
require __DIR__.'/../vendor/autoload.php';
if (PHP_VERSION_ID < 70000) {
include_once __DIR__.'/../var/bootstrap.php.cache';
}
$kernel = new AppKernel('prod',true);
if (PHP_VERSION_ID < 70000) {
$kernel->loadClassCache();
}
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

app_dev.php

<?php
use SymfonyComponentDebugDebug;
use SymfonyComponentHttpFoundationRequest;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);
// 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.');
}*/
require __DIR__.'/../vendor/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', false);
if (PHP_VERSION_ID < 70000) {
$kernel->loadClassCache();
}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

如果你想在生产服务器或类似的服务器中调试代码,我认为至少有一条黄金法则:不要修改app_dev.php或app.php。你可以像往常一样保持你的prod-env,同时,你可以用相应的环境(即"dev",你已经有了"prod")和端口运行webserver捆绑包。正如你所知道的,代码中的任何更改都是在dev中动态编译的,而在prod中,您必须清除缓存(甚至授予适当的web服务器权限)。据我所知,你不希望有任何不同,所以我建议恢复对app*.php脚本的更改,并相应地运行webserver捆绑包。

最新更新