简体   繁体   中英

How to start a Symfony server with environment variables from .env.test?

Is there any way to start the build in server with environment variables like DATABASE_URL from other environments like .env.test instead of .env ?

I want to use diffrent databases for dev and test but the Symfony server allways starts using dev.

I already tried stuff like:

APP_ENV=test bin/console server:start

Im using symfony4

When you run /bin/console you will see little help for this command and there you should see following flag:

-e, --env=ENV         The Environment name. [default: "dev"]

It means you can simply run bin/console --env=test server:start .

You need to change .env file to change environement from dev to prod, so i think the best way is make two files :

First one for local with dev configuration and another one in prod server with another configuration.

You can also configure your database in config/packages/doctrine.yaml like this :

doctrine:
    dbal:
        # configure these for your database server
        dbname:               ****
        host:                 127.0.0.1
        port:                 8889
        user:                 ****
        password:             ****

Hope this help.

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