feat: add .env support for coolify deployment

This commit is contained in:
fananazril
2026-06-11 19:27:21 +07:00
parent 0ae2768849
commit 3475cf16b4
4 changed files with 35 additions and 5 deletions
+8
View File
@@ -0,0 +1,8 @@
APP_NAME="WebGIS Sebaran Penduduk Miskin"
BASE_URL="https://your-coolify-domain.com"
# Database Configuration
DB_HOST=127.0.0.1
DB_USER=root
DB_PASS=secret
DB_NAME=poverty_map
+4
View File
@@ -0,0 +1,4 @@
.env
.DS_Store
/assets/uploads/*
!/assets/uploads/index.html
+19 -1
View File
@@ -3,8 +3,26 @@
// Konfigurasi Global Aplikasi // Konfigurasi Global Aplikasi
// ================================================================ // ================================================================
// Simple .env parser (for local use)
$envFile = __DIR__ . '/../.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) continue;
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value, " \t\n\r\0\x0B\"'"); // Strip whitespace and quotes
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}
// Base URL aplikasi // Base URL aplikasi
define('BASE_URL', 'http://localhost/webjir/poverty_map'); $defaultBaseUrl = 'http://localhost/webjir/poverty_map';
define('BASE_URL', getenv('BASE_URL') ?: $defaultBaseUrl);
define('BASE_PATH', dirname(__DIR__)); define('BASE_PATH', dirname(__DIR__));
// Koordinat default peta (Pontianak) // Koordinat default peta (Pontianak)
+4 -4
View File
@@ -2,10 +2,10 @@
// ================================================================ // ================================================================
// Konfigurasi Database // Konfigurasi Database
// ================================================================ // ================================================================
define('DB_HOST', 'localhost'); define('DB_HOST', getenv('DB_HOST') ?: 'localhost');
define('DB_USER', 'root'); define('DB_USER', getenv('DB_USER') ?: 'root');
define('DB_PASS', ''); define('DB_PASS', getenv('DB_PASS') !== false ? getenv('DB_PASS') : '');
define('DB_NAME', 'poverty_map'); define('DB_NAME', getenv('DB_NAME') ?: 'poverty_map');
define('DB_CHARSET','utf8mb4'); define('DB_CHARSET','utf8mb4');
function getDB(): PDO { function getDB(): PDO {