Environmental problem in Laravel

$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 what I type http://localhost/

, or http://chan.app

, App::environment()

always shows production

, so I can not change the configuration of the database for it.

0


source to share


2 answers


Due to security concerns, URL domains are prohibited in the environment. Laravel says to use hostnames .

This is why I doubt Laravel recognized your configuration correctly since both are on the same machine.

From 4.2 Upgrade Guide :

Environment detection updates

For security reasons, URL domains can no longer be used for the application environment. These values ​​are easy to spoof and allow attackers to change the environment for the request. You must convert your environment discovery to use hostnames (hostname command on Mac, Linux and Windows).

EDIT

Let's say you want a local and live environment.

1. Create folders for each configuration:

  • Create a folder local

    and live

    inside/app/config/

  • Within each of these folders, you create the config file (s) that you want to override from /app/config/

    ,

For example, in your live

(production) environment, you don't want to activate the option debug

.



  • Create a file app.php

    in a folder /app/config/live

    .
  • Internally, you simply return the parameters you want to override as defined in the original /app/config/app.php

    .

    return array('debug' => false);

In the local environment, "debug" will be set to true for development.

2. Add the environment to the structure:

In your file /bootstrap/start.php

:

$env = $app->detectEnvironment(array(
    'local' => array('local-machine-name'),
    'live' => array('yourdoamin.com')
));

      

What's the important part:

- Development (local): → machine name

- Production: -> root-url (yourdomain.com) which represents the name "machine"

See the environment configuration docs for more information .

0


source


Open CMD (Mac, Linux and Windows) and enter the command:

hostname

      



this will return the name of your computer. Then use this name:

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

      

0


source







All Articles