簡體   English   中英

Symfony將開發人員更改為產品

[英]Symfony change dev to prod

我有以下問題,我將symfony放在服務器上,將它在app_dev.php調試中更改為false,在app.php中更改為true,現在我應該在信息php bin /控制台中獲取有關我擁有固定版本的信息產品,為什么開發人員總是向我展示? 當然,調試欄將不會出現,並且進入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 env,同時,可以在相應的環境(即'dev',您已經具有“ prod”)和端口下運行Webserver捆綁軟件。 如您所知,代碼中的任何更改都是在dev中即時編譯的,在prod中,您必須清除緩存(甚至賦予適當的Web服務器權限)。 據我了解,您不希望與此有所不同,因此我建議將更改還原到app * .php腳本並相應地運行webserver捆綁軟件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM