fix: Lock .env strictly to CloudPanel user root /home/intaleqapp-saqel/.env

This commit is contained in:
Hamza-Ayed
2026-08-26 22:47:17 +03:00
parent 55c640609a
commit e800b5b057
+8 -22
View File
@@ -25,33 +25,19 @@ spl_autoload_register(function ($class) {
}
});
// 2. Load Environment Variables (Checks local and production server locations)
// 2. Load Environment Variables (Fixed Dedicated CloudPanel Path: /home/intaleqapp-saqel/.env)
try {
$candidatePaths = [
APP_ROOT . '/.env', // saqel/backend/.env
APP_ROOT . '/../.env', // saqel/.env
APP_ROOT . '/../../.env', // htdocs/saqel.intaleqapp.com/.env
'/home/intaleqapp-saqel/htdocs/saqel.intaleqapp.com/saqel/.env',
'/home/intaleqapp-saqel/htdocs/saqel.intaleqapp.com/.env',
'/home/intaleqapp-saqel/.env',
'/home/saqel/.env',
APP_ROOT . '/docker/.env',
];
// Fixed CloudPanel root path on server, with local fallback for local development
$env_file = file_exists('/home/intaleqapp-saqel/.env')
? '/home/intaleqapp-saqel/.env'
: APP_ROOT . '/.env';
$env_file = null;
foreach ($candidatePaths as $path) {
if (file_exists($path) && is_readable($path) && filesize($path) > 10) {
$env_file = realpath($path) ?: $path;
break;
}
}
if ($env_file) {
if (file_exists($env_file)) {
define('LOADED_ENV_PATH', $env_file);
\App\Core\Env::load($env_file);
} else {
define('LOADED_ENV_PATH', 'NONE_FOUND');
error_log("⚠️ [Env Warning] No valid .env file found in candidate paths. Expecting variables from server environment.");
define('LOADED_ENV_PATH', 'NOT_FOUND: ' . $env_file);
error_log("⚠️ [Env Warning] .env file not found at: {$env_file}");
}
} catch (\Exception $e) {
error_log('Env Load Error: ' . $e->getMessage());