Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and use environment variable .env yii2

Tags:

yii2

I want to create a file .env:

 FACEBOOK_CLIENT_ID=*****
 FACEBOOK_CLIENT_SECRET=*****

and use variable for config

'facebook' => [
                'class' => 'yii\authclient\clients\Facebook',
                'clientId' => env('FACEBOOK_CLIENT_ID'),
                'clientSecret' => env('FACEBOOK_CLIENT_SECRET'),
            ],
like image 592
Lê Hải Đăng Avatar asked Mar 20 '16 23:03

Lê Hải Đăng


People also ask

What is the default value of Yii_env?

You may define YII_ENV as one of the following values: prod: production environment. The constant YII_ENV_PROD will evaluate as true . This is the default value of YII_ENV if you do not define it. dev: development environment. The constant YII_ENV_DEV will evaluate as true.

How to add environment variables in Windows 10?

This option is below the "System Protection" option. Click on Environment Variables. After clicking, it will show a new window dialog called "Environment Variables". Decide which variable to add (User / System). Click the New option in any (User/System) section.

What are configurations in Yii?

Configurations are widely used in Yii when creating new objects or initializing existing objects. Configurations usually include the class name of the object being created, and a list of initial values that should be assigned to the object's properties.

What are environment variables and how to use them?

Environment variables are used when you need a setting loaded into your application and you did not want it hardcoded directly into your application, it makes sense and is a normal way to think. You normally keep database connection, API settings like basic-auth or bear-token, but you can keep other data in environment variables.


1 Answers

I have found the solution.

I use package vlucas/phpdotenv.

Thank for all

like image 105
Lê Hải Đăng Avatar answered Sep 30 '22 19:09

Lê Hải Đăng