diff --git a/application/admin/command/Install.php b/application/admin/command/Install.php index 835269dea4ff118a356e850b2368f5600c21c7da..5a36ab1972ab6f1f9dbc083662d28ec78e6f800a 100644 --- a/application/admin/command/Install.php +++ b/application/admin/command/Install.php @@ -215,6 +215,21 @@ class Install extends Command throw new Exception(__('The current permissions are insufficient to write the file %s', 'application/database.php')); } + // 生成Env配置文件 + $envFile = ROOT_PATH . '.env.sample'; + $envStr = @file_get_contents($envFile); + $callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) { + $field = "mysql" . ucfirst($matches[1]); + $replace = $$field; + return "{$matches[1]} = {$replace}" . PHP_EOL; + }; + $envConf = preg_replace_callback('/(hostname|database|username|password|hostport|prefix)\s*=\s*(.*?)\n/', $callback, $envStr); + + $result = @file_put_contents(ROOT_PATH . '.env', $envConf); + if (!$result) { + throw new Exception(__('The current permissions are insufficient to write the file %s', '.env')); + } + // 变更默认管理员密码 $adminPassword = $adminPassword ? $adminPassword : Random::alnum(8); $adminEmail = $adminEmail ? $adminEmail : "admin@admin.com";