#!/bin/bash
# Install PHP SQLite extension

echo "🔧 Installing PHP SQLite extension..."

# Check if running as root
if [ "$EUID" -ne 0 ]; then
    echo "Error: This script must be run as root (use sudo)"
    exit 1
fi

# Detect PHP version
PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
echo "Detected PHP version: $PHP_VERSION"

# Install SQLite extension
echo "Installing php${PHP_VERSION}-sqlite3..."
apt-get update -qq
apt-get install -y php${PHP_VERSION}-sqlite3

# Restart PHP-FPM
echo "Restarting PHP-FPM..."
systemctl restart php${PHP_VERSION}-fpm

# Verify installation
if php -m | grep -q sqlite3; then
    echo "✅ SQLite extension installed successfully"
    echo ""
    echo "Installed extensions:"
    php -m | grep -i sqlite
else
    echo "❌ Failed to install SQLite extension"
    exit 1
fi
