I understand with Laravel 5, it uses .env files so we can set specific enivornment values.
My question is, is there a way in Laravel 5, to say for example,
if ($SERVER_NAME == "my_production_server") {
$environment = "production"
}
And from that it uses production values. My thinking is, I'd like all the environments and their variables placed in one file or directory, or whatever so we can deploy the whole build without any manual intervention, and we can check this all into our code repository.
You could probably set the .env as:
Then in the database.php file in the config folder, you could set up the connections Host and Host2 to match the localhost and production values.
I have it like this For Laravel 5.0. I followed cjds guide but changed the code my specification. It requires no .env files.
Laravel 5 has made this a little harder than before but here's the way to do it. All you will need to do after this is change a value of your
.env
file and the environment will changeThe steps to do this are as follows
Look at your local
.env
installed by Laravel and change its contents to local or production or whatever else you needCreate 2 files
.local.env
and.production.env
Add default environment value:
.local.env
:APP_ENV=local
.production.env
:APP_ENV=production
Create new php file and named it,
environment.php
, save it into this folder:app/bootstrap/environment.php
Include your
environment.php
file in bootstrap file. Paste it inside yourbootstrap/app.php
file.Yay! You're done.
NOTE: If Laravel can't find a
.env
file it automatically uses.production.env
which makes it awesome for deploymentsCredit to http://developers.ph/laravel-framework/laravel-5/how-to-setup-multiple-environment-for-laravel-5-developers-way/