Changing default environment in Laravel 4

前端 未结 6 1791
我在风中等你
我在风中等你 2021-02-02 00:35

In Laravel 4 the default configuration environment is \'production\'. This means that if you run an artisan command without the --env option, it assumes the product

相关标签:
6条回答
  • 2021-02-02 01:06

    Thanks Antonio for prompting me to reconsider domain detection.

    $env = $app->detectEnvironment(array(
    (
        // Empty string is to set development as the default environment for 
        // artisan commands.
        'development' => array('dev.foo.com', ''),
        'test' => array('test.foo.com'),
        'production' => array('www.foo.com', 'foo.com'),
    ));
    

    Adding '' as a development domain effectively sets development as the default environment for artisan commands, presumably because the domain name is blank when the application is invoked from the command line. I tested and it seems anything == false will work. I also verified this does not interfere with the detection of the production or testing environments.

    0 讨论(0)
  • 2021-02-02 01:08

    You can try modifying app/start.php file to add second parameter on desired environment as TRUE i.e. to enable local environment it looks like

    $env = $app->detectEnvironment(array(
    
        'local' => array('homestead',true),
    
    ));
    
    0 讨论(0)
  • 2021-02-02 01:18

    In bootstrap/start.php you can set the environment:

    $env = $app->detectEnvironment(function()
    {
    
        return 'development';
    
    });
    

    But you can do many things like:

    $env = $app->detectEnvironment(array(
    
        'local' => array('your-machine-name'),
    
    ));
    

    And

    $env = $app->detectEnvironment(function()
    {
        return $_SERVER['MY_LARAVEL_ENV'];
    });
    
    0 讨论(0)
  • 2021-02-02 01:21
    $env = $app->detectEnvironment(array(
    
          'staging' => array('baichebao_test'),
          'local' => array('*.local', '*'),
     ));
    

    like my example, put your default environment in the last item of array, and add "*" to it's manager hostname. and it works in laravel 4.X

    0 讨论(0)
  • 2021-02-02 01:24

    One of the most elegant solution that I've found is from this blog post: http://stevegrunwell.com/blog/laravel-application-environment/

    The advantages:

    1. No need to hardcode an array of development machines into a git committed file start.php.
    2. Fallback to server environmental variables in production.
    3. Easy persist local development environment by modifying the environment.php file.
    0 讨论(0)
  • 2021-02-02 01:27

    In Laravel 4.2 you will not be able to do destructive artisan migrations without being prompted:

    Destructive migration operations now require confirmation or --force when being run in production.

    Change log for 4.2 is here

    0 讨论(0)
提交回复
热议问题