PDO::ERRMODE_EXCEPTION, ]); // 2. Create database if not exists $pdo->exec("CREATE DATABASE IF NOT EXISTS `$db_name` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); $pdo->exec("USE `$db_name` "); // 3. Update db/config.php $config_content = ' PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } catch (PDOException $e) { // If connection fails and we are not already on the install page, redirect to install.php if (basename($_SERVER[\'PHP_SELF\']) !== \'install.php\' && !headers_sent()) { header(\'Location: install.php\'); exit; } throw $e; } } return $pdo; }'; if (file_put_contents(__DIR__ . '/db/config.php', $config_content) === false) { throw new Exception("Could not write to db/config.php. Please check file permissions."); } // 4. Ensure migration_history table exists $pdo->exec("CREATE TABLE IF NOT EXISTS migration_history ( id INT AUTO_INCREMENT PRIMARY KEY, filename VARCHAR(255) NOT NULL UNIQUE, executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"); // 5. Run migrations $migrations_dir = __DIR__ . '/db/migrations/'; $migration_files = glob($migrations_dir . '*.sql'); sort($migration_files); // Get list of already executed migrations $stmt = $pdo->query("SELECT filename FROM migration_history"); $executed_migrations = $stmt->fetchAll(PDO::FETCH_COLUMN); foreach ($migration_files as $file_path) { $filename = basename($file_path); if (in_array($filename, $executed_migrations)) { continue; } $sql = file_get_contents($file_path); if ($sql) { // Split SQL by ; to handle multiple statements if any $pdo->exec($sql); // Record migration in history $stmt = $pdo->prepare("INSERT INTO migration_history (filename) VALUES (?)"); $stmt->execute([$filename]); } } // 6. Create Super User $hashed_pass = password_hash($admin_pass, PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (name, email, password, is_verified, role) VALUES (?, ?, ?, 1, 'Super User') ON DUPLICATE KEY UPDATE role = 'Super User'"); $stmt->execute([$admin_name, $admin_email, $hashed_pass]); // 7. Create lock file file_put_contents($lock_file, date('Y-m-d H:i:s')); $success = 'Installation successful! Admin account created. Redirecting to login...'; header('Refresh: 3; url=login.php'); } catch (Exception $e) { $error = 'Setup failed: ' . $e->getMessage(); } } } ?> Install — <?php echo htmlspecialchars($project_name); ?>

System Setup

Configure your database and administrator account.

Database
Super User

The installer will create the database, tables, and your admin account.