1
In Laravel there is the file .env.
In it I define my database connections, email, among other things.
Suppose I have three connections:
- Localhost
- Homologation
- Production
When I want to work on localhost I change the variable APP_ENV. I leave the value of this as local.
When I want to upload the files in the approval repository I leave the value of this variable as homo, and do git push origin master.
When I want to move up in production I change the value to production and do the push again.
All this for file connection database.php. It was the best solution I could find.
'mysql' => [
'driver' => 'mysql',
'host' => (env('APP_ENV') == 'local') ? env('DB_HOST_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_HOST_HOMO') : env('DB_HOST')),
'database' => (env('APP_ENV') == 'local') ? env('DB_DATABASE_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_DATABASE_HOMO') : env('DB_DATABASE')),
'username' => (env('APP_ENV') == 'local') ? env('DB_USERNAME_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_USERNAME_HOMO') : env('DB_USERNAME')),
'password' => (env('APP_ENV') == 'local') ? env('DB_PASSWORD_LOCAL') : ((env('APP_ENV') == 'homo') ? env('DB_PASSWORD_HOMO') : env('DB_PASSWORD')),
],
There’s a way I can automate this git or otherwise ?
NOTE: I created 2 repositories in Github, one of Homologation and one of Production to go up the project.
You spoke what I already knew. However, when I give
pushit replaces in the repository, whatever it is. So I did what I did.– Diego Souza
Is your repository also the site running the system? If that’s the case you would have to use
git_hooksto keep the config file in the same place, or else put your file.envsomewhere else and make Laravel carry from there– fernandosavio
I edited the answer
– fernandosavio
Now yes. Yes, my site is running with the repository files. I do
deploy. I’m gonna check it out frombash_profileand see what I can do. I can’t usegit_hooks.– Diego Souza
Here on my server do not have this file. Do you have to create ? And how would Laravel get its variables ? This file is created within the project ?
– Diego Souza
I never used
git_hooksalso... but this solution ofbash_profileis a good because it can be used in other projects too– fernandosavio
your server is Unix?
– fernandosavio
It’s a Linux, Ubuntu. Here’s a
.bashrc– Diego Souza
That, is the
.bashrc.– fernandosavio
Just have to see if this is the file that will be uploaded by the server user...
– fernandosavio
So, that’s my question. How to make in the Laravel files use the
.bashrcinstead of.env. There are several files, I may not even know what they are. I only know thedatabase.php– Diego Souza
The environment variables are from the operating system, not from Laravel. Dotenv arrow your variables to whole OS. You could enter the terminal and type
export APP_ENV="producao"that the entire process initiated at that terminal will have access to that information– fernandosavio
http://askubuntu.com/a/58828 you can edit the
/etc/environment– fernandosavio