Godô
Godô

Reputation: 113

How to set local environment in Laravel 4

I just want to set the local environment into Laravel 4.

In bootstrap/start.php I have:

$env = $app->detectEnvironment(array(
    'local' => ['laravel.dev', ''],
));

I tried change local to development index in array, but nothing works. I tried some tips of this page: http://laravel.com/docs/configuration... nothing.

I'm using artisan in console, that always say me:

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command?

What I might do to teach Lara that I'm on local environment?

Upvotes: 10

Views: 12554

Answers (3)

akash varlani
akash varlani

Reputation: 422

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

    $substr = substr(gethostname(), "-4");
    return ($substr == ".com" || $substr == ".net" || $substr == ".org") ? 'production' : 'local';

});

Upvotes: 0

Sebastian Sulinski
Sebastian Sulinski

Reputation: 6045

Following on from @The Alpha's great answer - here's a slight modification using array to check for local machines (when you work from more than one location):

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

    return in_array(
            gethostname(), 
            [
                'first local machine name', 
                'second local machine name'
            ]
        ) ? 
        'local' : 
        'production';

});

Upvotes: 3

The Alpha
The Alpha

Reputation: 146191

You may try this (In bootstrap/start.php file):

$env = $app->detectEnvironment(array(
    'local' => ['*.dev', gethostname()],
    'production' => ['*.com', '*.net', '*.org']
));

Also this is possible:

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

    return gethostname() == 'your local machine name' ? 'local' : 'production';
});

Upvotes: 43

Related Questions