fix: Detect exact .env location and report in /api/test/nabeh

This commit is contained in:
Hamza-Ayed
2026-08-26 22:43:18 +03:00
parent e4ad569d8c
commit 55c640609a
2 changed files with 33 additions and 15 deletions
+15 -7
View File
@@ -4,7 +4,7 @@
* Handles PSR-4 Autoloading, security settings, and strict error handling.
*/
// Define absolute path to application root
// Define absolute path to application root (saqel/backend)
define('APP_ROOT', dirname(__DIR__));
// 1. PSR-4 Autoloader
@@ -28,28 +28,36 @@ spl_autoload_register(function ($class) {
// 2. Load Environment Variables (Checks local and production server locations)
try {
$candidatePaths = [
APP_ROOT . '/.env',
APP_ROOT . '/../.env',
APP_ROOT . '/docker/.env',
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',
];
$env_file = null;
foreach ($candidatePaths as $path) {
if (file_exists($path)) {
$env_file = $path;
if (file_exists($path) && is_readable($path) && filesize($path) > 10) {
$env_file = realpath($path) ?: $path;
break;
}
}
if ($env_file) {
define('LOADED_ENV_PATH', $env_file);
\App\Core\Env::load($env_file);
} else {
error_log("⚠️ [Env Warning] No .env file found in candidate paths. Expecting variables from server environment.");
define('LOADED_ENV_PATH', 'NONE_FOUND');
error_log("⚠️ [Env Warning] No valid .env file found in candidate paths. Expecting variables from server environment.");
}
} catch (\Exception $e) {
error_log('Env Load Error: ' . $e->getMessage());
if (!defined('LOADED_ENV_PATH')) {
define('LOADED_ENV_PATH', 'ERROR: ' . $e->getMessage());
}
}
// 3. Configure Error Reporting based on environment