Home  >  Article  >  PHP Framework  >  How to configure environment variables in thinkphp6

How to configure environment variables in thinkphp6

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-01 11:36:442871browse

The thinkphp tutorial column below will introduce you to the method of configuring environment variables in thinkphp6. I hope it will be helpful to friends in need!

How to configure environment variables in thinkphp6

1. General configuration

configThe folder is tp6's regular configuration file, in the config folder we can modify the configuration inside or customize the configuration file. But do not modify the names and contents of these configuration files when we are not familiar with them, as this may cause the files to become unusable.

How to configure environment variables in thinkphp6

##2. envEnvironment variable definition

Configurationenv

When we download thinkphp6, there will be an environment variable instance file

.example.env in the root directory. You can directly Change .example.env to .env for modification.

APP_DEBUG = true

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai

[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = username
PASSWORD = password
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true

[LANG]
default_lang = zh-cn

Among them,

APP_DEBUG is to enable the tp6 test mode, APP_DEBUG = true means that the test mode has been enabled.

Calling env

If you want to use env, you must first introduce the

think\facade\Env facade class to obtain the environment variables There is no need to be case sensitive.

If you want to call the database, you need to modify

DATABASE (database), USERNAME (user name), PASSWORD in .env (password) content needs to be modified as follows:

DATABASE = tp
USERNAME = root
PASSWORD = root

At the same time,

database.php also needs to be modified as follows:

// 数据库名
'database' => env('database.database', 'tp'),
// 用户名
'username' => env('database.username', 'root'),
// 密码
'password' => env('database.password', 'root'),

Related recommendations:

The latest 10 thinkphp video tutorials

The above is the detailed content of How to configure environment variables in thinkphp6. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn