ale10257 / yii2-app-basic-with-env-settings
Yii 2 Basic Project Template with environment settings
Requires
- php: >=5.4.0
- yiisoft/yii2: ~2.0.14
- yiisoft/yii2-bootstrap: ~2.0.0
- yiisoft/yii2-swiftmailer: ~2.0.0
Requires (Dev)
- codeception/base: ~2.3.0
- codeception/specify: ~0.4.6
- codeception/verify: ~0.4.0
- yiisoft/yii2-debug: ~2.0.0
- yiisoft/yii2-faker: ~2.0.0
- yiisoft/yii2-gii: ~2.0.0
This package is not auto-updated.
Last update: 2025-03-02 22:08:20 UTC
README
Yii 2 Basic Project Template with environment settings
Yii 2 Basic Project Template is a skeleton Yii 2 application best for rapidly creating small projects.
Why .env?
You should never store sensitive credentials in your code. Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments – such as database credentials or credentials for 3rd party services – should be extracted from the code into environment variables.
Basically, a .env
file is an easy way to load custom configuration variables
that your application needs without having to modify .htaccess files or
Apache/nginx virtual hosts. This means you won't have to edit any files outside
the project, and all the environment variables are always set no matter how you
run your project - Apache, Nginx, CLI, and even PHP 5.4's built-in webserver.
It's WAY easier than all the other ways you know of to set environment
variables, and you're going to love it!
- NO editing virtual hosts in Apache or Nginx
- NO adding
php_value
flags to .htaccess files - EASY portability and sharing of required ENV values
- COMPATIBLE with PHP's built-in web server and CLI runner
Install
composer create-project --prefer-dist --stability=dev ale10257/yii2-app-basic-with-env-settings .
After install
cd your/project
cp example.env .env
Edit your settings in .env file
YII_DEBUG=true
YII_ENV='dev'
DB_HOST='localhost'
DB_NAME='my_db'
DB_USER='root'
DB_PASSWD=''
DB_CHARSET='utf8'
# other environment settings ...
In your project, example:
'dsn' => 'mysql:host=' . $_ENV['DB_HOST'] . ';dbname=' . $_ENV['DB_NAME'];
Enjoy :)