Home > Article > PHP Framework > How to configure environment variables in thinkphp6
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!
config
The 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.
Environment variable definition
Configurationenv
.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-cnAmong them,
APP_DEBUG is to enable the
tp6 test mode,
APP_DEBUG = true means that the test mode has been enabled.
Calling env
think\facade\Env facade class to obtain the environment variables There is no need to be case sensitive.
DATABASE (database),
USERNAME (user name),
PASSWORD in .env
(password) content needs to be modified as follows:
DATABASE = tp USERNAME = root PASSWORD = rootAt 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!