1、修改php.ini配置文件,首先找到如下配置信息
;variables_order
;Default Value: “EGPCS”
;Development Value: “GPCS”
;Production Value: “GPCS”
修改为:
;variables_order
Default Value: “EGPCS”
;Development Value: “GPCS”
;Production Value: “GPCS”
2、重启Apache或者Nginx
Apache重启:systemctl restart httpd
Nginx重启:systemctl restart nginx
3、检查Thinkphp目录下的Base.php文件是否已存在如下代码,无则添加
if (is_file(ROOT_PATH . ‘.env’)) {
env=pars e in i file(ROO T PATH . ′.en v ′,true);foreach(env = parse_ini_file(ROOT_PATH . '.env', true); foreach ( env=parseinifile(ROOTPATH.′.env′,true);foreach(env as $key => $val) {
name=EN V PREFIX.strtoupper(name = ENV_PREFIX . strtoupper( name=ENVPREFIX.strtoupper(key);
if (is_array(KaTeX parse error: Expected '}', got 'EOF' at end of input: … foreach (val as $k => $v) {
$item = KaTeX parse error: Expected group after '_' at position 9: name . '_̲' . strtoupper(k);
putenv(“item=item= item=v”);
}
} else {
putenv(“name=name= name=val”);
//加入这一句
ENV[_ENV[ ENV[name]=$val;
}
}
}
4、最后就可以使用.env里面的配置了
[app]
debug = true
trace = true
[database]
hostname = localhost
database = test
username = test
password = ‘test@’
hostport = 3306
prefix = pr_
注意:如果.env里面有特殊符文,记得加上单引号或者双引号。如:上面的password