[ 'name' => 'PHP Version (>= 8.0)', 'status' => version_compare(PHP_VERSION, '8.0.0', '>='), 'current' => PHP_VERSION ], 'pdo_mysql' => [ 'name' => 'PDO MySQL Extension', 'status' => extension_loaded('pdo_mysql'), 'current' => extension_loaded('pdo_mysql') ? 'Loaded' : 'Missing' ], 'curl' => [ 'name' => 'cURL Extension (Required for Licensing)', 'status' => extension_loaded('curl'), 'current' => extension_loaded('curl') ? 'Loaded' : 'Missing' ], 'config_writable' => [ 'name' => 'db/config.php Writable', 'status' => is_writable(__DIR__ . '/../db/config.php'), 'current' => is_writable(__DIR__ . '/../db/config.php') ? 'Yes' : 'No' ], 'root_writable' => [ 'name' => 'Root Directory Writable', 'status' => is_writable(__DIR__ . '/..'), 'current' => is_writable(__DIR__ . '/..') ? 'Yes' : 'No' ] ]; $allOk = true; foreach ($requirements as $req) { if (!$req['status']) $allOk = false; } } // Step 2: Database if ($step === 2 && $_SERVER['REQUEST_METHOD'] === 'POST') { $host = $_POST['db_host'] ?? ''; $name = $_POST['db_name'] ?? ''; $user = $_POST['db_user'] ?? ''; $pass = $_POST['db_pass'] ?? ''; try { $pdo = new PDO("mysql:host=$host;dbname=$name", $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); // Save to config.php $configContent = " PDO::ERRMODE_EXCEPTION,\n PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,\n ]);\n }\n return \$pdo;\n}\n"; file_put_contents(__DIR__ . '/../db/config.php', $configContent); header("Location: index.php?step=3"); exit; } catch (PDOException $e) { $error = "Database Connection Failed: " . $e->getMessage(); } } // Step 3: Super Admin if ($step === 3 && $_SERVER['REQUEST_METHOD'] === 'POST') { require_once __DIR__ . '/../db/config.php'; $adminUser = $_POST['admin_user'] ?? ''; $adminPass = $_POST['admin_pass'] ?? ''; $adminEmail = $_POST['admin_email'] ?? ''; try { $pdo = db(); // Import full schema if available $schemaFile = __DIR__ . '/../complete_schema.sql'; if (file_exists($schemaFile)) { $host = DB_HOST; $name = DB_NAME; $user = DB_USER; $pass = DB_PASS; // Use mysql CLI for reliable import $cmd = sprintf( 'mysql -h %s -u %s %s %s < %s', escapeshellarg($host), escapeshellarg($user), ($pass ? '-p' . escapeshellarg($pass) : ''), escapeshellarg($name), escapeshellarg($schemaFile) ); exec($cmd, $output, $returnVar); if ($returnVar !== 0) { // Fallback to manual execution if CLI fails $sql = file_get_contents($schemaFile); $pdo->exec($sql); } } else { // Fallback to base tables if complete_schema.sql is missing $pdo->exec("CREATE TABLE IF NOT EXISTS role_groups ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, permissions TEXT )"); $pdo->exec("CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, email VARCHAR(100), phone VARCHAR(20), group_id INT, status ENUM('active', 'inactive') DEFAULT 'active', profile_pic VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )"); } // Ensure Admin Role exists (might be in schema but just in case) $stmt = $pdo->prepare("SELECT id FROM role_groups WHERE name = 'Administrator'"); $stmt->execute(); $role = $stmt->fetch(); if (!$role) { $pdo->exec("INSERT INTO role_groups (name, permissions) VALUES ('Administrator', 'all')"); $roleId = $pdo->lastInsertId(); } else { $roleId = $role['id']; } // Insert Admin User (Use ON DUPLICATE KEY UPDATE to handle existing user from schema) $hashedPass = password_hash($adminPass, PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (username, password, email, group_id, status) VALUES (?, ?, ?, ?, 'active') ON DUPLICATE KEY UPDATE password = VALUES(password), email = VALUES(email), group_id = VALUES(group_id), status = 'active'"); $stmt->execute([$adminUser, $hashedPass, $adminEmail, $roleId]); header("Location: index.php?step=4"); exit; } catch (Exception $e) { $error = "Setup Failed: " . $e->getMessage(); } } // Step 4: Finish if ($step === 4) { file_put_contents($lockFile, date('Y-m-d H:i:s')); } ?>
Configure your application in minutes
Installation completed successfully. Your system is now secure and ready to use.
installed.lock file has been created.