问题
$env = $app->detectEnvironment(array(
'local' => array('*localhost*'),
'test' => array('chan.app'),
));
This is how I set in boostrap/start.php, and I set ip in hosts file
127.0.0.1 localhost 127.0.0.1 chan.app
No matter I type http://localhost/
or http://chan.app
, App::environment()
always reveal production
, therefore I can't change database config for it.
回答1:
Open your CMD (Mac, Linux, and Windows) and type the command:
hostname
this will return the name of your computer. Then use that name:
$env = $app->detectEnvironment(array(
'local' => array('ComputerName'),
));
回答2:
Because of security issues, the use of url domains in environment is forbidden. Laravel says to use hostnames instead.
This is why I doubt, that Laravel would recognise (detect) your configuration correctly, as both are on the same machine.
From the 4.2 Upgrade Guide:
Environment Detection Updates
For security reasons, URL domains may no longer be used to detect your application environment. These values are easily spoofable and allow attackers to modify the environment for a request. You should convert your environment detection to use machine host names (hostname command on Mac, Linux, and Windows).
EDIT
Let's say, you want a local and a live environment.
1. Create folders for each configuration:
- Create a folder
local
&live
inside/app/config/
- Inside each of those folders you create the config file(s) you wish to override from
/app/config/
,
For example, in your live
(production) environment, you don't want to have the debug
option activated.
- Create a file
app.php
in the/app/config/live
folder. Inside, you'll just return the desired options to override, as defined in the original
/app/config/app.php
.return array('debug' => false);
In the local environment, 'debug' would be set to true, for development.
2. Add the environment to the framework:
In your /bootstrap/start.php
file:
$env = $app->detectEnvironment(array(
'local' => array('local-machine-name'),
'live' => array('yourdoamin.com')
));
That's the important part:
- Development (local): --> machine name
- Production: --> root-url (yourdomain.com) which represents the "machine" name
See the docs about environment config for further information.
来源:https://stackoverflow.com/questions/26879482/environment-issue-in-laravel