yii2-environment Environment class for Yii 2

  1. Installation
  2. Usage
  3. Documentation

Environment class for Yii 2, used to set configuration for console and web apps depending on the server environment.

Software License Build Status Quality Score Packagist Version Total Downloads


If you do not have Composer, you may install it by following the instructions at getcomposer.org.

You can then install this package using the following command:

php composer.phar require "janisto/yii2-environment" "*"

or add

"janisto/yii2-environment": "*"

to the require section of your application's composer.json file.


web index.php
require(dirname(__DIR__) . '/vendor/autoload.php');

$env = new \janisto\environment\Environment(dirname(__DIR__) . '/config');
(new yii\web\Application($env->web))->run();

or if you have multiple configuration locations

require(dirname(__DIR__) . '/vendor/autoload.php');

$env = new \janisto\environment\Environment([
    dirname(__DIR__) . '/common/config',
    dirname(__DIR__) . '/backend/config'
(new yii\web\Application($env->web))->run();
console yii
#!/usr/bin/env php

require(__DIR__ . '/vendor/autoload.php');

// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));

$env = new \janisto\environment\Environment(__DIR__ . '/config');
$exitCode = (new yii\console\Application($env->console))->run();

Use yii

export YII_ENV='dev' && ./yii


See examples/.

1 0
1 follower
Yii Version: 2.0
License: (not set)
Category: Others
Developed by: janisto
Created on: Oct 27, 2014
Last updated: 9 years ago

Related Extensions