feat: Implement an installation process including a setup UI, database migrations, and admin account creation.

This commit is contained in:
dyzulk
2026-01-17 13:57:08 +07:00
parent e8ffea2c58
commit b245f31236
4 changed files with 55 additions and 1 deletions

View File

@@ -54,8 +54,20 @@ fi
# 4. Set Permissions
echo "Step 4: Setting permissions..."
chown -R www:www .
chmod -R 755 .
chmod +x mivo
chmod -R 755 public
# Ensure Database directory is writable
if [ ! -d "app/Database" ]; then
mkdir -p app/Database
chown www:www app/Database
fi
chmod 775 app/Database
if [ -f "app/Database/database.sqlite" ]; then
chmod 664 app/Database/database.sqlite
fi
# If there's a storage directory (MVC style usually has one)
if [ -d "storage" ]; then
chmod -R 775 storage

View File

@@ -15,8 +15,12 @@ class InstallController extends Controller {
header('Location: /login');
exit;
}
$permissions = $this->checkPermissions();
return $this->view('install');
return $this->view('install', [
'permissions' => $permissions
]);
}
public function process() {
@@ -25,6 +29,13 @@ class InstallController extends Controller {
exit;
}
$permissions = $this->checkPermissions();
if (!$permissions['db_writable'] || !$permissions['root_writable']) {
\App\Helpers\FlashHelper::set('error', 'Izin Ditolak', 'Pastikan folder app/Database dan root direktori dapat ditulis oleh server web.');
header('Location: /install');
exit;
}
$username = $_POST['username'] ?? 'admin';
$password = $_POST['password'] ?? 'admin';
@@ -63,6 +74,17 @@ class InstallController extends Controller {
}
}
private function checkPermissions() {
$dbDir = ROOT . '/app/Database';
$envFile = ROOT . '/.env';
return [
'db_writable' => is_writable($dbDir),
'env_writable' => file_exists($envFile) ? is_writable($envFile) : is_writable(ROOT),
'root_writable' => is_writable(ROOT)
];
}
private function isInstalled() {
// Check if .env exists and APP_KEY is set to something other than the default/example
$envPath = ROOT . '/.env';

0
app/Database/.gitkeep Normal file
View File

View File

@@ -20,6 +20,26 @@
</div>
<div class="card p-6 sm:p-8 space-y-6">
<?php if (isset($permissions) && (!$permissions['db_writable'] || !$permissions['root_writable'])): ?>
<div class="bg-red-500/10 border border-red-500/20 rounded-lg p-4 mb-6">
<div class="flex items-center gap-3 text-red-500 mb-2">
<i class="ph-bold ph-warning text-lg"></i>
<h4 class="font-bold text-sm">Peringatan Izin Direktori</h4>
</div>
<ul class="text-xs text-red-400 space-y-1 list-disc list-inside">
<?php if (!$permissions['db_writable']): ?>
<li>Folder <code>app/Database</code> harus writable (chmod 775/777).</li>
<?php endif; ?>
<?php if (!$permissions['root_writable']): ?>
<li>Root direktori harus writable untuk membuat file <code>.env</code>.</li>
<?php endif; ?>
</ul>
<p class="text-[10px] text-red-400/70 mt-3 pt-3 border-t border-red-500/10">
Silakan perbaiki izin folder di server Anda sebelum melanjutkan.
</p>
</div>
<?php endif; ?>
<form action="/install" method="POST" class="space-y-6">
<!-- Steps UI -->