운영 서버용 .env 설정 자동 복사 및 적용
This commit is contained in:
63
fix_env.php
63
fix_env.php
@@ -1,34 +1,49 @@
|
||||
<?php
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
echo "=== Specialized Search in /home/webservice/sales_org ===\n";
|
||||
echo "=== Production Environment Auto-Configurator ===\n";
|
||||
|
||||
$targetFile = '/home/webservice/sales_org/.env';
|
||||
$sourceEnv = '/home/webservice/sales_org/.env';
|
||||
$targetEnv = '/home/webservice/sales/.env';
|
||||
|
||||
if (file_exists($targetFile)) {
|
||||
echo "[EXISTS] Found .env in sales_org!\n";
|
||||
if (is_readable($targetFile)) {
|
||||
$content = file_get_contents($targetFile);
|
||||
echo "--- Content (Masked) ---\n";
|
||||
if (isset($_GET['apply']) && $_GET['apply'] === 'true') {
|
||||
if (file_exists($sourceEnv)) {
|
||||
echo "Reading configuration from $sourceEnv...\n";
|
||||
$content = file_get_contents($sourceEnv);
|
||||
|
||||
// Parse source credentials
|
||||
$db_host = 'localhost';
|
||||
$db_name = 'chandj';
|
||||
$db_user = 'codebridge';
|
||||
$db_pass = '';
|
||||
|
||||
foreach (explode("\n", $content) as $line) {
|
||||
if (stripos($line, 'DB_') !== false) {
|
||||
if (stripos($line, 'PASS') !== false) echo explode('=', $line)[0] . "=********\n";
|
||||
else echo $line . "\n";
|
||||
}
|
||||
$line = trim($line);
|
||||
if (strpos($line, '=') === false) continue;
|
||||
list($key, $val) = explode('=', $line, 2);
|
||||
if ($key === 'DB_HOST') $db_host = $val;
|
||||
if ($key === 'DB_NAME') $db_name = $val;
|
||||
if ($key === 'DB_USER') $db_user = $val;
|
||||
if ($key === 'DB_PASS') $db_pass = $val;
|
||||
}
|
||||
|
||||
// Construct new .env for current server
|
||||
$newContent = "APP_URL=https://sales.codebridge-x.com/\n";
|
||||
$newContent .= "DB_HOST=$db_host\n";
|
||||
$newContent .= "DB_NAME=$db_name\n";
|
||||
$newContent .= "DB_USER=$db_user\n";
|
||||
$newContent .= "DB_PASS=$db_pass\n";
|
||||
$newContent .= "DOCUMENT_ROOT=/home/webservice/sales\n";
|
||||
|
||||
if (file_put_contents($targetEnv, $newContent)) {
|
||||
echo "SUCCESS: New .env created at $targetEnv\n";
|
||||
echo "You can now log in to the sales management system.\n";
|
||||
echo "\nIMPORTANT: Delete fix_env.php after verification!\n";
|
||||
} else {
|
||||
echo "ERROR: Failed to write to $targetEnv. Check directory permissions.\n";
|
||||
}
|
||||
} else {
|
||||
echo "[ERROR] Found but Permission Denied for www-data. Current user: " . `whoami` . "\n";
|
||||
echo "ERROR: Source .env not found at $sourceEnv\n";
|
||||
}
|
||||
} else {
|
||||
echo "[NOT FOUND] $targetFile does not exist.\n";
|
||||
}
|
||||
|
||||
echo "\n=== Trying common PHP config files ===\n";
|
||||
$configs = [
|
||||
'/home/webservice/api/lib/mydb.php',
|
||||
'/home/webservice/mng/lib/mydb.php',
|
||||
'/home/webservice/script/pull_sales.sh'
|
||||
];
|
||||
|
||||
foreach($configs as $c) {
|
||||
if(file_exists($c)) echo "[FILE EXISTS] $c\n";
|
||||
echo "Usage: Append ?apply=true to execute the configuration copy.\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user