Files
coolcoth.com/config/config.php
T
Lucanlee 6d3962574c perf/security: V0.9.5-0.9.6 db_pending_upgrades 缓存 + config 凭据外置
- V0.9.5 (P3): db_pending_upgrades() 加 static 请求内缓存,同请求只算一次
- V0.9.6 (安全): config.php 移除明文密码,改从 gitignored 的 config.secret.php 或
  环境变量读取;新增 config.secret.php.example 模板;.gitignore 忽略 config/config.secret.php
  (修复 Webhook reset 反复覆盖明文凭据的隐患;服务器部署前需自建 config.secret.php)
2026-08-09 00:34:54 +08:00

52 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 全局配置(不含敏感凭据,可安全入库)
*
* 敏感凭据(数据库密码 / 后台密码)从以下优先级读取,避免明文写入仓库:
* 1) 同级 config.secret.phpgitignored,需服务器侧自建;git reset --hard 不会被清除,建一次即可)
* 2) 环境变量 COOLCOTH_DB_PASS / COOLCOTH_ADMIN_PASS
* 3) 本文件中的占位(为空 → 连接失败,仅作本地演示占位)
*
* 部署步骤(务必在下次 Webhook 部署前完成,否则 DB 连接 / 后台登录会失败):
* 在服务器 /www/wwwroot/coolcoth.com/config/ 下新建 config.secret.php,内容参考 config.secret.php.example
*/
$secret = [];
if (file_exists(__DIR__ . '/config.secret.php')) {
$secret = require __DIR__ . '/config.secret.php';
}
$secret = array_merge([
'db_pass' => '',
'admin_pass' => '',
], $secret);
return [
'app' => [
'name' => '酷冰甲 · 降温服',
'slogan' => '科技降温 · 清凉一夏',
'driver' => 'mysql', // file | mysql —— 本地已切到 MySQL,与远端(宝塔)保持一致
'admin_path' => 'admin',
'timezone' => 'Asia/Shanghai',
],
'db' => [
'mysql' => [
'host' => '127.0.0.1',
'port' => 3306,
'dbname' => 'coolcoth_comf',
'user' => 'coolcoth_comf',
'pass' => $secret['db_pass'] ?: (getenv('COOLCOTH_DB_PASS') ?: ''),
'charset' => 'utf8mb4',
],
'file' => [
'dir' => __DIR__ . '/../storage/data',
],
],
// 后台登录账号(文件模式 / 首次安装)
'admin' => [
'username' => 'admin',
'password' => $secret['admin_pass'] ?: (getenv('COOLCOTH_ADMIN_PASS') ?: ''),
// 本地规则红线:生产环境(mysql 模式)必须关闭配置文件兜底账号,禁用默认密码后门。
// 仅本地演示(file 模式)可临时置 true。远端已实测默认密码可登录,已置 false 封堵。
'allow_config_fallback' => false,
],
];