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

Tell Laravel your machine name be it localhost or local IP or .dev domain and it'll detect that it's running locally and pull in local configurations. I tend to use (until Homestead) local as my machine name.

Last updated 1 year ago.
0

This is how I do it:

$env = $app->detectEnvironment(array(
	'local'         => array('OUTERHEAVEN'),
    'production'    => array('domain.com')
));

I'm a Windows user and my PC name is OUTERHEAVEN. I don't know what will it be in mac/linux. I created a folder named "local" in app/config and put a copy of database.php inside it. app/config/database.php contains actual/production configuration and app/config/local/database.php contains development/local configuration. Laravel uses app/config/local/database.php if environment is local, otherwise it uses app/config/database.php if environment is production.

Excuse my English.

Last updated 1 year ago.
0

so, here is what I do.

in my /bootstrap/start.php file, the $env variable is set like the following

$env = $app->detectEnvironment(function() {

    return getenv('APP_ENV') ?: 'LOCAL';

});

this will check for the existence of an APP_ENV global and use that, otherwise it will default to LOCAL

all of my production servers (NGINX) have APP_ENV set to PROD which puts me in production mode the moment I deploy, otherwise I'm defaulted to my development environment (local)

... hope this helps.

Last updated 1 year ago.
0

dannalloway's suggestion is a good one, this is what I'm using now and works well and doesn't require setting any environment variables. Your hostname can sometimes change on your local computer, and its different if you're using other dev machines, but it probably never changes on your production server, so you can also do this in that case:

$env = $app->detectEnvironment(function() {
    return gethostname() == 'prod.production.com' ? 'production' : 'local';
});

http://www.php.net/manual/en/function.gethostname.php

Last updated 1 year ago.
0

thanks to all, my confusion was resolved, if I understand correctly the environment is set in the $app-> detectEnvironment (...), that returns $env which is used elsewhere only to read current env,

junior that I am, I would have expected: $ env = $ app-> detectEnvironment (...); $ app-> SetEnvironment ($env);

although, perhaps it is not useful in practice, it seems strange to me can't set an environment arbitrary name, not depending by domain, namemachine, ... thing that you can do with syntax suggested by danalloway $ env = $ app-> detectEnvironment (function () { return 'myenv'; }); i'm sorry too for my english :)

Last updated 1 year ago.
0

but WHERE ? do you set that environment global to something? what I am seeing here is just ways to detect in which environment you are. You are saying, IF the variable was set to whatever the name of your PC is, use the local config, otherwise the production. BUT WHERE? do you set that global?

Last updated 1 year ago.
0

In Laravel 5 all you have to do is change the details inside the .env file in your root directory. .gitignore the file.

Last updated 1 year ago.
0

I think danalloway's solution should really be the defacto. Basing configs on hostnames/ips/servernames is not something scalable and seems like something out of a 2002's web developer's book. These days you should imagine deploying out to several webheads/cache servers/databases most likely in a cloud environment where those servers and hostnames can change all of the time. When it comes to the apache/nginx/lighttpd configs, setting an APP_ENV variable there is a no-brainer.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

sarduk sarduk Joined 18 May 2014

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.