0

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

  • I think it should be 3 separate .env files `.env` is used on production, then `.env.staging` is on your staging. Finally `.env.local` on your development machine – lozadaOmr Apr 03 '15 at 04:19
  • @lozadaOmr thanks for sharing a good idea .i try to built same route to 3 mode :) now . – Kornkrit Leelhaphunt Apr 03 '15 at 04:24
  • @lozadaOmr i found some good way too . This link **http://stackoverflow.com/questions/26365621/laravel-5-doesnt-read-values-from-dot-env-files** – Kornkrit Leelhaphunt Apr 03 '15 at 04:33
  • 2
    Just a correction my previous comment was based on using Laravel 4.2, apparently things are different in Laravel 5 see dynamic's answer. – lozadaOmr Apr 03 '15 at 08:27

1 Answers1

4

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>
Kyslik
  • 8,217
  • 5
  • 54
  • 87
dynamic
  • 46,985
  • 55
  • 154
  • 231
  • 1
    Exactly, I dont understand why people don't read documentation, its all there, and also it is mentioned in one (recent) episode of Laravel Podcasts. – Kyslik Apr 03 '15 at 10:42