new configs for deployment

This commit is contained in:
Araya's Project
2026-06-11 00:12:43 +07:00
parent bc415cd947
commit 5b316b2ef6
7 changed files with 25 additions and 101 deletions
+6 -33
View File
@@ -1,45 +1,18 @@
# Git
.git
.gitignore
.gitattributes
# Docker files (tidak perlu masuk image)
*.md
**/README.md
docker-compose.yml
.dockerignore
# Dokumentasi
README.md
**/README.md
# SQL files (hanya dipakai untuk init DB, bukan bagian app)
**/setup.sql
**/schema.sql
**/database.sql
**/seed.sql
database/
# Seed scripts (hanya untuk dev)
**/seed.php
# OS & editor junk
.DS_Store
Thumbs.db
desktop.ini
*.swp
*.swo
*~
# IDE
.vscode/
.idea/
*.code-workspace
# Logs
*.log
logs/
# Environment files (jangan masuk image)
database/
.env
.env.*
!.env.example
.DS_Store
.vscode/
*.log
+1 -6
View File
@@ -1,17 +1,12 @@
FROM php:8.2-apache
# Enable mod_rewrite for clean URLs and .htaccess support
RUN a2enmod rewrite
# Install PHP extensions needed: mysqli (sig-03), pdo + pdo_mysql (sig-01, sig-02)
RUN docker-php-ext-install mysqli pdo pdo_mysql
# Allow .htaccess overrides in /var/www/html
RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf
# Copy all project files into Apache web root
COPY . /var/www/html/
# Fix file permissions
RUN chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html
&& chmod -R 755 /var/www/html
+7 -15
View File
@@ -1,7 +1,5 @@
<?php
// FILE INI HANYA UNTUK INISIALISASI DATABASE
// HAPUS SETELAH DIPAKAI!
// HAPUS FILE INI SETELAH DIPAKAI!
$host = getenv('DB_HOST') ?: 'localhost';
$user = getenv('DB_USER') ?: 'root';
$pass = getenv('DB_PASS') ?: '';
@@ -12,8 +10,6 @@ if ($conn->connect_error) {
}
$sqls = file_get_contents(__DIR__ . '/database/init.sql');
// Pisah per statement
$statements = array_filter(array_map('trim', explode(';', $sqls)));
$success = 0;
@@ -29,16 +25,12 @@ foreach ($statements as $sql) {
}
echo "<h2>DB Init Result</h2>";
echo "<p style='color:green'>✅ $success statements executed successfully.</p>";
echo "<p style='color:green'>✅ $success statements OK</p>";
if (!empty($errors)) {
echo "<h3 style='color:red'>Errors (" . count($errors) . "):</h3>";
foreach ($errors as $e) {
echo "<pre style='background:#fee;padding:8px'>$e</pre>";
}
echo "<h3 style='color:orange'>Errors (" . count($errors) . "):</h3>";
foreach ($errors as $e) echo "<pre style='background:#fee;padding:8px'>$e</pre>";
} else {
echo "<p style='color:green'>✅ All done! Semua database berhasil dibuat.</p>";
echo "<p style='color:red'><b>⚠️ HAPUS FILE INI SEKARANG dari repo!</b></p>";
echo "<p style='color:green'><b>✅ Semua database berhasil dibuat!</b></p>";
echo "<p style='color:red'><b>⚠️ Sekarang hapus file ini dari repo!</b></p>";
}
$conn->close();
$conn->close();
+1 -23
View File
@@ -3,30 +3,8 @@ services:
build: .
expose:
- "80"
depends_on:
db:
condition: service_healthy
environment:
DB_HOST: swc8c4cgcg0s40g04c8k0gso
DB_USER: mysql
DB_PASS: yPsQNavb6V4loDnXIQz1uluEaQBflV7YsrZBx6HSOXgnK54L85vi1nTdAfWmswDl
restart: unless-stopped
db:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: Cb6aGo2ccTVo10wdtU3QM0Ch2yEE8Z1PR9OIXUvmKfAQrCmntWabaQa3JFqi0Vz0
MYSQL_DATABASE: sig_spbu
volumes:
- db_data:/var/lib/mysql
- ./database/init.sql:/docker-entrypoint-initdb.d/init.sql
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u root -prootpassword || exit 1"]
interval: 10s
timeout: 10s
retries: 15
start_period: 30s
volumes:
db_data:
restart: unless-stopped
+2 -8
View File
@@ -1,6 +1,4 @@
<?php
// Konfigurasi koneksi database
// Mendukung environment variable Docker (DB_HOST) maupun hardcoded untuk Laragon
define('DB_HOST', getenv('DB_HOST') ?: 'localhost');
define('DB_NAME', 'sig_spbu');
define('DB_USER', getenv('DB_USER') ?: 'root');
@@ -10,11 +8,7 @@ define('DB_CHARSET', 'utf8mb4');
function getDB(): PDO {
static $pdo = null;
if ($pdo !== null) return $pdo;
$dsn = sprintf(
'mysql:host=%s;dbname=%s;charset=%s',
DB_HOST, DB_NAME, DB_CHARSET
);
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=%s', DB_HOST, DB_NAME, DB_CHARSET);
try {
$pdo = new PDO($dsn, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
@@ -28,4 +22,4 @@ function getDB(): PDO {
exit;
}
return $pdo;
}
}
+2 -8
View File
@@ -1,17 +1,11 @@
<?php
/**
* Koneksi database (PDO).
* Mendukung environment variable Docker (DB_HOST) maupun hardcoded untuk Laragon.
*/
define('DB_HOST', getenv('DB_HOST') ?: '127.0.0.1');
define('DB_PORT', '3306');
define('DB_NAME', 'sig_mapping');
define('DB_USER', getenv('DB_USER') ?: 'root');
define('DB_PASS', getenv('DB_PASS') ?: '');
function db(): PDO
{
function db(): PDO {
static $pdo = null;
if ($pdo === null) {
$dsn = sprintf('mysql:host=%s;port=%s;dbname=%s;charset=utf8mb4', DB_HOST, DB_PORT, DB_NAME);
@@ -22,4 +16,4 @@ function db(): PDO
]);
}
return $pdo;
}
}
+6 -8
View File
@@ -1,19 +1,17 @@
<?php
define('DB_HOST', getenv('DB_HOST') ?: 'localhost');
define('DB_USER', getenv('DB_USER') ?: 'root');
define('DB_PASS', getenv('DB_PASS') ?: '');
define('DB_NAME', 'sig_bansos');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$host = getenv('DB_HOST') ?: 'localhost';
$user = getenv('DB_USER') ?: 'root';
$pass = getenv('DB_PASS') ?: '';
$db = 'sig_bansos';
$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
http_response_code(500);
die(json_encode(['success' => false, 'message' => 'Koneksi database gagal: ' . $conn->connect_error]));
}
$conn->set_charset('utf8mb4');
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Headers: Content-Type');