From 3475cf16b49bcb2f1845033e48b2d0cfd1f45c9d Mon Sep 17 00:00:00 2001 From: fananazril Date: Thu, 11 Jun 2026 19:27:21 +0700 Subject: [PATCH] feat: add .env support for coolify deployment --- .env.example | 8 ++++++++ .gitignore | 4 ++++ config/config.php | 20 +++++++++++++++++++- config/database.php | 8 ++++---- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 .env.example create mode 100644 .gitignore diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7fcfdd3 --- /dev/null +++ b/.env.example @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f25900f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.env +.DS_Store +/assets/uploads/* +!/assets/uploads/index.html diff --git a/config/config.php b/config/config.php index 07e1e8f..f207eb0 100644 --- a/config/config.php +++ b/config/config.php @@ -3,8 +3,26 @@ // 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 -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__)); // Koordinat default peta (Pontianak) diff --git a/config/database.php b/config/database.php index 0bb4cdd..36f7a0c 100644 --- a/config/database.php +++ b/config/database.php @@ -2,10 +2,10 @@ // ================================================================ // Konfigurasi Database // ================================================================ -define('DB_HOST', 'localhost'); -define('DB_USER', 'root'); -define('DB_PASS', ''); -define('DB_NAME', 'poverty_map'); +define('DB_HOST', getenv('DB_HOST') ?: 'localhost'); +define('DB_USER', getenv('DB_USER') ?: 'root'); +define('DB_PASS', getenv('DB_PASS') !== false ? getenv('DB_PASS') : ''); +define('DB_NAME', getenv('DB_NAME') ?: 'poverty_map'); define('DB_CHARSET','utf8mb4'); function getDB(): PDO {