Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据库配置硬编码问题 #11

Open
buexplain opened this issue Feb 21, 2019 · 0 comments
Open

数据库配置硬编码问题 #11

buexplain opened this issue Feb 21, 2019 · 0 comments

Comments

@buexplain
Copy link

现在的数据库配置是写死在config/database.php文件里面的,不利于开发与部署,建议采用.env进行配置,大概代码如下:
config/database.php文件部分修改:

use think\facade\Env;

return [
// 数据库类型
'type'            => 'mysql',
'hostname'        => Env::get('database.hostname', '127.0.0.1'),
// 数据库名
'database'        => Env::get('database.database', ''),
// 用户名
'username'        => Env::get('database.username', 'root'),
// 密码
'password'        => Env::get('database.password', ''),
// 端口
'hostport'        => Env::get('database.hostport', ''),
];

站点目录下新增.env.example文件:

[common]
app_debug = true
app_trace = false

[database]
hostname = 数据库地址
database = 数据库名称
username = 账号
password = 密码
hostport = 3306
prefix   = rh_

部署的时候直接执行 cp .env.example .env,然后再根据环境配置 .env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant