在 根目录 创建一个.env 文件
.env 的内容
"database"="mb_tv"
hostname = "ip"
username="root"
password="123456"
port="39188"
dbprefix="t_"
redis_host = "localhost"
redis_port = "6379"
redis_auth = ""
在CI 框架的入口文件index.php 中 加入以下代码
$env_dir = $_SERVER['DOCUMENT_ROOT']."/".".env";
$_ENV = [];
if(is_file($env_dir)){
$_ENV = parse_ini_file($env_dir, true);
}
在 数据库配置文件
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => $_ENV['hostname']?$_ENV['hostname']:"mysql",
'username' => $_ENV['username']?$_ENV['username']:"root",
'password' => $_ENV['password']?$_ENV['password']:"123456",
'port'=>$_ENV['port']?$_ENV['port']:"3306",
'database' => $_ENV['database']?$_ENV['database']:"app_tv",
'dbdriver' => 'mysqli',
'dbprefix' => $_ENV['dbprefix']?$_ENV['dbprefix']:"t_",
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
在 redis 文件 中
$config['redis_default']['host'] = $_ENV['redis_host']?$_ENV['redis_host']:"redis"; // IP address or host $config['redis_default']['port'] = $_ENV['redis_port']?$_ENV['redis_port']:"6379"; // Default Redis port is 6379 $config['redis_default']['auth'] = $_ENV['redis_auth']?$_ENV['redis_auth']:"";
来源:oschina
链接:https://my.oschina.net/hongjiang/blog/4329072