Support the ongoing development of Laravel.io →
Configuration Architecture
Last updated 1 year ago.
0

Create a file in your root called .env. This will be detected and used if found.

In this file you can add APP_ENV=local to decide your environment.

Last updated 1 year ago.
0

How does Laravel detect which environment to use? It used to be based on hostname (or something more sophisticated if it was needed)

Last updated 1 year ago.
0

Hey LordMonoxide,

I know this post is 2 months old and you may have already found your answer... but I figured I'd answer it for anyone else who saw it.

In the old Laravel 4 way you could find inside of bootstrap/start.php

   $env = $app->detectEnvironment(array(
	'local' => array('homestead'),
   ));

That is how Laravel knew the current environment. This has changed as you already pointed out. The new process is to specific the environment inside of <project_root>/.env

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file

If you look inside of config/database.php for instance you will find

	'mysql' => [
		'driver'    => 'mysql',
		'host'      => env('DB_HOST', 'localhost'),
		'database'  => env('DB_DATABASE', 'forge'),
		'username'  => env('DB_USERNAME', 'forge'),
		'password'  => env('DB_PASSWORD', ''),
                ...
	],

This env helper method will let you pull out environment variables from the .env file you created.

If you are wondering how you might know about all the variables Laravel configs use then you can use .env-example as a starting point. Just copy that .env-example file to .env.

Next if you open the .gitignore file you will find that .env has been added. This means that you will either need to take it out (not recommended) and commit it to source.

The better approach I think is to just create this .env on each one of your environments and keep it out of your source code repository. This way you can have different database settings on your development machine than your staging/testing/production servers.

Last updated 9 years ago.
0

The issue I have with this new environment configuration extends from using homestead 2.0 on Windows. Not sure if on a mac it works the same.

I have node, composer and PHP5 installed locally on my machine. Why? because the CLI runs much faster locally on my machine and on large seeds it makes a big BIG difference. It also allows me to perform many routine operations without having to ssh into the vm.

Problem:

Because there is only one .env to reflect the environment I can only choose the homestead as the environment with the correct Database ports as they exist in the VM.

In L4 in addition to the homestead environment i had a local environment where i switched out the vm native ports with the "forwarded ports". This alllows me to seamlessly use git bash without ssh'ing into the vm where everything performs much slower. I mainly use postgresql and unlike mysql where you can define the port in php.ini, there is no such directive that i have found for postgresql in php.ini.

Temporary Fix:

I go into the VirtualBox NAT settings and change port forwarding settings for postgresql back to 5420 and then I dont have to SSH into the VM. I could edit the .rb and change it there, however, vagrant will fail to start since it will complain of collisions.

So if anyone knows how to tackle this issue on a more permanent basis, id love to hear about it.

Thanks Vic

0

Hi vmadev,

Running too many different softwares may cause unknown errors. For Windows, it is more productive and less headache if you use Laragon, a Wamp replacement and fully Laravel support. Homestead is fine when testing.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.