LoginSignup
18
18

More than 5 years have passed since last update.

CodeIgniterで複数環境の取り扱いが微妙だったので改造してみた

Last updated at Posted at 2013-04-28

3.x系では同様の方法で環境を切り替えられるようになっているようです。


CodeIgniterで複数環境を扱うとき皆さんどうしているのでしょうか。

参考)
複数の環境の取扱い
http://codeigniter.jp/user_guide_ja/general/environments.html
configの設定
http://codeigniter.jp/user_guide_ja/libraries/config.html#environments

index.phpに記述してある以下のコードで環境を変えているのですが

index.php
define('ENVIRONMENT', 'development');

本番環境にしたいときは以下のように修正するってことです。

index.php
define('ENVIRONMENT', 'production');

index.phpも含めてgitに入ったりしているわけだからそれを環境変えた時に変更して置いておくのもなぁ…

index.phpの上の部分を以下のように修正

index.php
define('ENVIRONMENT', isset($_SERVER["ENVIRONMENT"]) ?  $_SERVER["ENVIRONMENT"] : 'development');

サーバーの環境変数で環境が決定できるようにしました。

nginx+php-fpmの場合

server {
    ...
    location ~* \.php$ {
        ...
        fastcgi_param  ENVIRONMENT production;
    }
}

apacheの場合

<VirtualHost *:80>
    ...
    SetEnv ENVIRONMENT production
</VirtualHost>

こんな感じでENVIRONMENTを設定してやるといけます。

18
18
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
18
18