Kornkrit Leelhaphunt
Kornkrit Leelhaphunt

Reputation: 168

Laravel 5 : How to set environment mode

I mm trying to set 3 mode in laravel 5 Example : mode local , staging , production

I am setting environment 3 mode in .env but I try to separate to .local.env , .staging.env and production.env someone here have any idea to do like this ?

Now i'm try in .env -> APP_ENV to 3 mode right now :)

Thank you

Upvotes: 0

Views: 2806

Answers (1)

dynamic
dynamic

Reputation: 48091

Other answers/comments are wrong.

You only store one .env per environment. That is:

  • Your local machine will have a .env with your local config
  • The staging maching will have a .env with your staging config, and
  • Your production maching will have a .env with your production config

So it is always one .env file per machine. Laravel will load that config from that file.

note that .env file is in .gitignore, .env.example is not


When testing on local machine using PHPUnit you can add env variables in phpunit.xml

<php>
    <env name="APP_ENV" value="testing"/>
    <env name="APP_DEBUG" value="true"/>
    <env name="APP_KEY" value="some crazy value"/>
    <env name="DB_DRIVER" value="sqlite"/>
    <env name="DB_DATABASE" value=":memory:"/>
    <env name="CACHE_DRIVER" value="array"/>
    <env name="SESSION_DRIVER" value="array"/>
</php>

Upvotes: 4

Related Questions