LoginSignup
16
15

More than 5 years have passed since last update.

Laravel4で環境によって設定を変えたい時にどうするか

Posted at

bootstrap/start.phpでホスト名とその時の環境名を指定。

$env = $app->detectEnvironment(array(

    'staging'    => array('staging-web'),
    'production' => array('production-web*'),
    'local'      => array('local.*', '*.local', '*.lan' ),

));

設定の切り替えはapp/config/下のディレクトリを切り替えることで分けて適用できる。app/config/に共通の設定を書き、環境名のディレクトリに固有の設定(部分だけ書いて上書きが可能)。

app/config/database.php
app/config/local/database.php
app/config/production/database.php

サーバ上でどの環境が適用されるのかはartisanでチェックできる。

% php artisan env
Current application environment: local
16
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15