Toskan
Toskan

Reputation: 14931

only one .env file for local, staging and production?

i have different passwords on all stages. I have different settings too in the .env file.

What I end up doing is to upload the .env file manually after a file change to the stage, manually setting the correct passwords and keys. is there no better way, maybe official laravel way?

so again:

i say have: .env

DB_DATABASE=myDBnameLocal
DB_USERNAME=myuserLOCAL
DB_PASSWORD=mypasswordLOCAL

different values for staging etc

I rather have 3 different files, and a 4th file where I set the environment to

say a .stage where I define which environment my app is in. And depending on that value, I load the correct .env file.

is there a way to do something like this or is there a way to do it different altogether?

say define all passwords in one big file and call things like this:

DB_DATABASE_LOCAL=myDBnameLocal
DB_USERNAME_LOCAL=myuserLOCAL
DB_PASSWORD_LOCAL=mypasswordLOCAL

DB_DATABASE_PRODUCTION=myDBnamePRODUCTION
DB_USERNAME_PRODUCTION=myuserPRODUCTION
DB_PASSWORD_PRODUCTION=mypasswordPRODUCTION

even though this does not seem to be very safe.

Upvotes: 1

Views: 638

Answers (1)

Rehan Manzoor
Rehan Manzoor

Reputation: 2753

Well they way you're doing right now is the right way, This is the laravel way to keep your environment files different for each environment. Because now you know that what each of your environments got, and you can change any file whenever your environment parameter is changed e.g. say your db is changed at staging area.

And keeping production setting in .env for local is lethal, Why?

  1. First it is not secure to keep your production setting on your local machine.
  2. By keeping your production/staging setting at the same file will make you use IF and BUTS e.g.

    if( env('APP_ENV') === 'local' ) { 
       $username = env('DB_LOCAL_USERNAME');
    }
    
  3. Now you need to keep the record at which environment your variables are changed and keep all the variables in sync on all environments.

That's all from my point of view.

Upvotes: 1

Related Questions