fix: Detect exact .env location and report in /api/test/nabeh
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user