简体   繁体   English

使本地Symfony 2.8应用程序像在产品环境中一样运行

[英]Make a local Symfony 2.8 app act like it's in a prod environment

I have an application based on Symfony 2.8. 我有一个基于Symfony 2.8的应用程序。 A feature is working well in my local dev environment but failing in production. 某个功能在我本地的开发环境中运行良好,但无法生产。 I want to make my local environment use prod mode in order to hopefully replicate the problem. 我希望使我的本地环境使用prod模式,以便希望重现该问题。 What I have tried: 我试过的

export SYMFONY_ENV=prod
app/console cache:clear --no-warmup

This appeared at first to be working, as I got a message about the cache being cleared in the prod environment, but when I loaded the app, the debug toolbar was visible and said I was in dev mode. 起初这似乎是可行的,因为我收到有关在产品环境中清除缓存的消息,但是当我加载应用程序时,调试工具栏是可见的,并说我处于开发模式。

I have also tried looking in both parameters.yml and config.yml for any denotation of the environment. 我还尝试在parameter.yml和config.yml中查找环境的任何表示形式。 I didn't find anything. 我什么都没找到

What should I try next? 接下来我应该尝试什么?

The answer can depend on a lot of factors: what web-server is used, what web-server config is used, do you use php-fpm or else, etc. 答案可能取决于许多因素:使用什么Web服务器,使用什么Web服务器配置,是否使用php-fpm等等。

Console commands like "export SYMFONY_ENV=prod" set environment only for console commands in the same session. 诸如“ export SYMFONY_ENV = prod”之类的控制台命令仅为同一会话中的控制台命令设置环境。 But they can't affect your web server behavior. 但是它们不会影响您的Web服务器行为。

When you open a page of your project in a browser, the application doesn't know anything about commands what you have typed in a terminal. 当您在浏览器中打开项目的页面时,应用程序对您在终端中键入的命令一无所知。 If you see a debug console probably the app entry point is "web/app_dev.php", and the environment is defined here like: 如果您看到调试控制台,则应用程序入口点可能是“ web / app_dev.php”,并且在此处定义了环境:

// web/app_dev.php // web / app_dev.php

$kernel = new AppKernel('dev', true); $ kernel = new AppKernel('dev',true);

Try to change 'dev' by 'prod' 尝试通过“ prod”更改“ dev”

Well, in symfony2 dev mode is being accessed through file web/app_dev.php , prod - web/app.php . 好吧,在symfony2 开发模式下,可通过文件web / app_dev.phpprod - web / app.php访问 So if you are using your own local web-server (apache or nginx), in order to see the app in prod mode, you may want to provide your web-server the default symfony configuration, eg as described here : https://symfony.com/doc/2.8/setup/web_server_configuration.html#nginx 因此,如果您使用自己的本地网络服务器(apache或nginx),则为了以生产模式查看该应用程序,可能需要为您的网络服务器提供默认的symfony配置,例如此处所述: https:// symfony.com/doc/2.8/setup/web_server_configuration.html#nginx

In case you are using symfony built-in web-server, you may want to use the solution ox160d05d provided. 如果您使用的是symfony内置的Web服务器,则可能要使用提供的解决方案ox160d05d。 I would recommend using own local web-server though. 我建议尽管使用自己的本地网络服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM