LoginSignup
3
3

More than 5 years have passed since last update.

Phalcon configの環境切り分け方法

Posted at

fastcgi_param で任意の変数(ここではAPP_ENV)を設定することで、php-fpmへ環境変数を渡せます

nginx.conf
location @app {
    fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # Nginx側で環境設定を切り替え
    fastcgi_param APP_ENV   development;

    include fastcgi_params;
}
config.php
return new \Phalcon\Config([
    'production' => [
        'database' => [ 'host' => 'production.db' ]
    ],
    'staging' => [
        'database' => [ 'host' => 'staging.db' ]
    ],
    'development' => [
        'database' => [ 'host' => 'development.db' ]
    ],
]);
index.php
$di->setShared('config', function () {

   $config = include APP_PATH . "/config/config.php";

   return $config->get(getenv('APP_ENV'));

});
3
3
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
3
3