Update: 2026-05-15 21:50:12
This commit is contained in:
@@ -15,15 +15,33 @@ $searchPaths = [
|
|||||||
__DIR__ . '/../../../..', // htdocs/
|
__DIR__ . '/../../../..', // htdocs/
|
||||||
__DIR__ . '/../../../../..', // home directory
|
__DIR__ . '/../../../../..', // home directory
|
||||||
posix_getpwuid(posix_getuid())['dir'] ?? '', // PHP-detected home dir
|
posix_getpwuid(posix_getuid())['dir'] ?? '', // PHP-detected home dir
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] ?? ''
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$envData = [];
|
||||||
|
|
||||||
foreach ($searchPaths as $path) {
|
foreach ($searchPaths as $path) {
|
||||||
if (!empty($path) && file_exists($path . '/.env')) {
|
if (!empty($path) && file_exists($path . '/.env')) {
|
||||||
try {
|
try {
|
||||||
$dotenv = Dotenv::createImmutable($path);
|
// First try native parsing (bulletproof)
|
||||||
$dotenv->load();
|
$parsed = parse_ini_file($path . '/.env', false, INI_SCANNER_RAW);
|
||||||
$envLoaded = true;
|
if ($parsed !== false) {
|
||||||
break;
|
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) {
|
} catch (Exception $e) {
|
||||||
// Try next path
|
// Try next path
|
||||||
}
|
}
|
||||||
@@ -34,7 +52,7 @@ if (!$envLoaded) {
|
|||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'success' => false,
|
'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;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user