php - 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 Symfony\Component\Debug\ErrorHandler
但是,输入 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 Symfony\Component\HttpFoundation\Request;
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 Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
// 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 环境,同时,您可以使用相应的环境(即“dev”,您已经拥有“prod”)和端口来运行 webserver 包。如您所知,代码中的任何更改都是在 dev 中即时编译的,而在 prod 中您必须清除缓存(甚至给予适当的网络服务器权限)。据我了解,您不希望有任何与此不同的内容,因此我建议恢复对 app*.php 脚本的更改并相应地运行网络服务器包。
推荐阅读
- c - 函数 read_new_int 的问题
- firebase - 了解 Firestore 收集中的数据何时结束
- reactjs - React-Select :选项显示为空白
- node-redis - node_redis - 如何获取密钥的 TTL?
- python - 收到内容编码的响应:gzip,但未能对其进行解码
- ios - 取多个滑块值的平均值
- javascript - 承诺的价值问题 Promise { value }
- angular - 在前端展示业务对象的正确方法是什么?
- reactjs - Flow 需要 HOC 中 props 的类型注解
- arrays - Pascal - 数组的用户输入名称