Update: 2026-05-15 21:50:12
This commit is contained in:
@@ -15,15 +15,33 @@ $searchPaths = [
|
||||
__DIR__ . '/../../../..', // htdocs/
|
||||
__DIR__ . '/../../../../..', // home directory
|
||||
posix_getpwuid(posix_getuid())['dir'] ?? '', // PHP-detected home dir
|
||||
$_SERVER['DOCUMENT_ROOT'] ?? ''
|
||||
];
|
||||
|
||||
$envData = [];
|
||||
|
||||
foreach ($searchPaths as $path) {
|
||||
if (!empty($path) && file_exists($path . '/.env')) {
|
||||
try {
|
||||
$dotenv = Dotenv::createImmutable($path);
|
||||
$dotenv->load();
|
||||
$envLoaded = true;
|
||||
break;
|
||||
// First try native parsing (bulletproof)
|
||||
$parsed = parse_ini_file($path . '/.env', false, INI_SCANNER_RAW);
|
||||
if ($parsed !== false) {
|
||||
foreach ($parsed as $key => $value) {
|
||||
$_ENV[$key] = trim($value);
|
||||
$_SERVER[$key] = trim($value);
|
||||
putenv("$key=" . trim($value));
|
||||
}
|
||||
$envLoaded = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallback to Dotenv library
|
||||
if (class_exists('Dotenv\Dotenv')) {
|
||||
$dotenv = Dotenv\Dotenv::createImmutable($path);
|
||||
$dotenv->load();
|
||||
$envLoaded = true;
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Try next path
|
||||
}
|
||||
@@ -34,7 +52,7 @@ if (!$envLoaded) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '.env file not found. Searched paths: ' . implode(', ', array_filter($searchPaths))
|
||||
'message' => '.env file not found or could not be parsed. Searched paths: ' . implode(', ', array_filter($searchPaths))
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user