简体   繁体   English

如何使用 symfony 环境 dev 和 prod

[英]How to use symfony environments dev and prod

This may seem a dumb question, I need my symfony 3 app to behave different in production than it does in my local machine.这似乎是一个愚蠢的问题,我需要我的 symfony 3 应用程序在生产中的行为与在本地机器中的行为不同。 I know there is an entry point for each env, app.php and app_dev.php我知道每个 env、app.php 和 app_dev.php 都有一个入口点

I don't want to change the application web/.htaccess file because it's followed by git, I was expecting an 'env' var or something similar in app/config.yml but there is also a config.yml and a config_dev.yml, so it has to be another place where I can define if I am working with prod or dev env.我不想更改应用程序 web/.htaccess 文件,因为它后跟 git,我期待 app/config.yml 中有一个 'env' var 或类似的东西,但也有一个 config.yml 和一个 config_dev.yml ,所以它必须是另一个我可以定义我是使用 prod 还是 dev env 的地方。

Documentation says that I need to setup my apache server to use either web/app.php or web/app_dev.php, and this is my question.文档说我需要设置我的 apache 服务器以使用 web/app.php 或 web/app_dev.php,这是我的问题。 I'm using apache 2.4 and I tried using the following directive:我正在使用 apache 2.4,我尝试使用以下指令:

<VirtualHost *:8000>
    <directory>
        ...
        DirectoryIndex app_dev.php
    </directory>
</VirtualHost>

I restarted apache, but when I type localhost:8000 in my browser, it keeps using the default app.php, I need my apache server to use app_dev.php, I don't want to use the built-in server because it gets buggy after a while.我重新启动了 apache,但是当我在浏览器中输入localhost:8000时,它一直使用默认的 app.php,我需要我的 apache 服务器使用 app_dev.php,我不想使用内置服务器,因为它会一段时间后,马车。

Can anyone please help me with the apache configuration to use the dev env?任何人都可以帮助我使用 apache 配置来使用开发环境吗?

I think you have the following problems: regardless of which DirectoryIndex you define, the server also picks ups some settings from .htaccess .我认为您有以下问题:无论您定义哪个DirectoryIndex ,服务器也会从.htaccess获取一些设置。 Could it be possible that you have another reference to app.php in there, like RewriteRule ^(.*)$ app.php [QSA,L] ?你有没有可能在那里有另一个对app.php引用,比如RewriteRule ^(.*)$ app.php [QSA,L]

Then you could do the following: move that exact setting from .htaccess to your server configuration, both locally and on the production server.然后您可以执行以下操作:将确切的设置从.htaccess移动到您的服务器配置,包括本地和生产服务器上。 Then you can keep all other settings independent from your enviroment.然后,您可以使所有其他设置独立于您的环境。

If this does not help yet, please share the content of .htaccess .如果这还没有帮助,请分享.htaccess的内容。

Another way of solving could be to use a recent Symfony version and put everything that might change between environments in the .env file.另一种解决方法是使用最新的 Symfony 版本,并将环境之间可能发生变化的所有内容放在.env文件中。 Don't put it under version control, as this file might contain sensitive information.不要将其置于版本控制之下,因为此文件可能包含敏感信息。 Then have a look at the current basics: you no longer have a app.php and app_dev.php , as the changes were only little.然后看看当前的基础知识:你不再有app.phpapp_dev.php ,因为变化很小。 A common index.php is used, and it reads all current settings from .env使用了一个通用的index.php ,它从.env读取所有当前设置

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

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