简体   繁体   中英

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. I know there is an entry point for each env, app.php and 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.

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. I'm using apache 2.4 and I tried using the following directive:

<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.

Can anyone please help me with the apache configuration to use the dev env?

I think you have the following problems: regardless of which DirectoryIndex you define, the server also picks ups some settings from .htaccess . Could it be possible that you have another reference to app.php in there, like 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. Then you can keep all other settings independent from your enviroment.

If this does not help yet, please share the content of .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. 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. A common index.php is used, and it reads all current settings from .env

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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