# OakTix Installation Guide

## Table of Contents
1. [Requirements](#requirements)
2. [cPanel Installation](#cpanel-installation)
3. [VPS/Server Installation](#vps-server-installation)
4. [Post-Installation](#post-installation)
5. [Troubleshooting](#troubleshooting)

## Requirements

### Server Requirements
- PHP 8.2 or higher
- MySQL 8.0 or higher (or MariaDB 10.3+)
- Apache 2.4+ with mod_rewrite
- Composer 2.x (for manual installation)
- SSL Certificate (recommended for production)

### PHP Extensions Required
- BCMath
- Ctype
- cURL
- DOM
- Fileinfo
- JSON
- Mbstring
- OpenSSL
- PDO
- PDO MySQL
- Tokenizer
- XML
- GD
- exif

### Check PHP Extensions
Create a file `phpinfo.php` with:
```php
<?php phpinfo(); ?>
```
Access it via browser and verify all extensions are enabled.

## cPanel Installation

### Step 1: Upload Files
1. Download the OakTix ZIP file
2. Log in to your cPanel
3. Go to File Manager
4. Navigate to `public_html` (or your domain folder)
5. Upload the ZIP file
6. Extract the ZIP file

### Step 2: Create Database
1. In cPanel, go to "MySQL Database Wizard"
2. Create a new database (e.g., `youruser_oaktix`)
3. Create a database user
4. Add user to database with ALL PRIVILEGES
5. Note down the database name, username, and password

### Step 3: Run Installation Wizard
1. Open your browser
2. Navigate to `https://yourdomain.com/install/`
3. Follow the on-screen instructions:
   - **Step 1**: Verify server requirements
   - **Step 2**: Enter database credentials
   - **Step 3**: Create admin account
   - **Step 4**: Configure site settings
   - **Step 5**: Complete installation

### Step 4: Delete Install Folder
**IMPORTANT**: After successful installation:
1. Go to File Manager
2. Delete the `/install` folder completely
3. This is critical for security

### Step 5: Set Up Cron Job (Optional)
For automated database backups:
1. In cPanel, go to "Cron Jobs"
2. Add new cron job:
   ```
   0 2 * * * /usr/bin/php /home/username/public_html/artisan backup:database
   ```
   Replace `username` with your cPanel username

## VPS/Server Installation

### Step 1: Install Dependencies

**Ubuntu/Debian:**
```bash
sudo apt update
sudo apt install php8.2 php8.2-cli php8.2-fpm php8.2-mysql php8.2-xml php8.2-mbstring php8.2-curl php8.2-zip php8.2-gd php8.2-bcmath
sudo apt install mysql-server nginx composer
```

**CentOS/RHEL:**
```bash
sudo yum install php php-cli php-fpm php-mysql php-xml php-mbstring php-curl php-zip php-gd php-bcmath
sudo yum install mysql-server nginx composer
```

### Step 2: Configure Database
```bash
sudo mysql -u root -p
CREATE DATABASE oaktix CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'oaktix_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON oaktix.* TO 'oaktix_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
```

### Step 3: Upload and Configure
```bash
cd /var/www
git clone https://github.com/your-repo/oaktix.git
cd oaktix
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
```

Edit `.env` file with your database credentials.

### Step 4: Run Migrations
```bash
php artisan migrate --force
php artisan db:seed --force
php artisan storage:link
```

### Step 5: Set Permissions
```bash
sudo chown -R www-data:www-data /var/www/oaktix
sudo chmod -R 755 /var/www/oaktix/storage
sudo chmod -R 755 /var/www/oaktix/bootstrap/cache
```

### Step 6: Configure Nginx
Create `/etc/nginx/sites-available/oaktix`:
```nginx
server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/oaktix/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
```

Enable the site:
```bash
sudo ln -s /etc/nginx/sites-available/oaktix /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```

## Post-Installation

### 1. Secure Your Installation
- Change default admin password
- Delete `/install` folder
- Set strong database password
- Enable HTTPS (SSL certificate)

### 2. Configure Paystack
1. Sign up at https://paystack.com
2. Get your API keys from dashboard
3. Login to OakTix admin
4. Go to Settings → Payment
5. Enter your Paystack keys
6. Start with test mode

### 3. Configure Email
1. Go to Settings → Email
2. Enter SMTP credentials
3. Test email delivery
4. Common SMTP settings:
   - **Gmail**: smtp.gmail.com:587
   - **SendGrid**: smtp.sendgrid.net:587
   - **Mailgun**: smtp.mailgun.org:587

### 4. Customize Your Site
1. Go to Settings → General
2. Upload your logo
3. Update site name and description
4. Configure social media links
5. Update SEO settings

### 5. Create Categories
1. Go to Categories
2. Add relevant event categories
3. Customize icons and colors

## Troubleshooting

### 500 Internal Server Error
1. Check `.htaccess` file exists in `public/` folder
2. Ensure `mod_rewrite` is enabled
3. Check file permissions (755 for directories, 644 for files)
4. Check Laravel logs in `storage/logs/`

### Database Connection Error
1. Verify database credentials in `.env`
2. Ensure database exists
3. Check database user permissions
4. Verify MySQL is running

### Permission Denied Errors
```bash
chmod -R 755 storage/
chmod -R 755 bootstrap/cache/
chmod -R 644 storage/logs/
```

### Missing Vendor Folder
Run: `composer install`

### CSS/JS Not Loading
1. Ensure `APP_URL` in `.env` matches your domain
2. Run: `php artisan storage:link`
3. Clear cache: `php artisan cache:clear`

### Email Not Sending
1. Check SMTP settings
2. Verify firewall allows outbound port 587
3. Check spam folders
4. Review email logs

## Getting Help

If you encounter issues:
1. Check the logs in `storage/logs/`
2. Review this installation guide
3. Contact support at support@oaktix.com.ng

## Security Checklist

- [ ] Changed default admin password
- [ ] Deleted `/install` folder
- [ ] Set strong database password
- [ ] Enabled HTTPS
- [ ] Configured firewall rules
- [ ] Set up regular backups
- [ ] Updated all dependencies
- [ ] Disabled debug mode in production
