# Production Deployment Guide

## Issues Fixed

### 1. Composer Cache Directory Permissions
**Problem**: Composer cannot create cache directory `/var/www/.cache/composer/files/`
**Solution**: 
```bash
sudo mkdir -p /var/www/.cache/composer/files/
sudo chown -R www-data:www-data /var/www/.cache
sudo chmod -R 755 /var/www/.cache
```

### 2. Duplicate Seeder Files
**Problem**: Ambiguous class resolution warnings due to duplicate seeder files in both `database/seeds/` and `database/seeders/`
**Solution**: 
- ✅ Updated `composer.json` to only autoload `database/seeders/`
- ✅ Copied all missing seeders from `database/seeds/` to `database/seeders/`
- ✅ Updated `DatabaseSeeder.php` to include all necessary seeders

### 3. Abandoned Packages
**Warning**: Some packages are deprecated but still functional:
- `strebl/adldap` → Use `adldap2/adldap2` instead
- `fzaninotto/faker` → No replacement suggested (still works)

## Production Deployment Steps

### 1. Run Cleanup Script
```bash
chmod +x scripts/cleanup_seeds.sh
./scripts/cleanup_seeds.sh
```

### 2. Install Dependencies
```bash
sudo -u www-data composer install --optimize-autoloader --no-dev
```

### 3. Set Proper Permissions
```bash
sudo chown -R www-data:www-data /var/www/seraph3
sudo chmod -R 755 /var/www/seraph3/storage
sudo chmod -R 755 /var/www/seraph3/bootstrap/cache
```

### 4. Environment Configuration
```bash
# Copy production environment file
cp .env.production .env

# Generate application key
php artisan key:generate

# Clear all caches
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
```

### 5. Database Setup
```bash
# Run migrations
php artisan migrate --force

# Seed database (if needed)
php artisan db:seed --force
```

### 6. Optimize for Production
```bash
# Optimize autoloader
composer dump-autoload --optimize

# Cache configuration
php artisan config:cache

# Cache routes
php artisan route:cache

# Cache views
php artisan view:cache
```

## Docker Production Setup

### 1. Build Production Images
```bash
docker-compose -f docker-compose.production.yaml build
```

### 2. Start Services
```bash
docker-compose -f docker-compose.production.yaml up -d
```

### 3. Run Application Setup
```bash
# Access the app container
docker-compose -f docker-compose.production.yaml exec app bash

# Run the deployment steps inside the container
./scripts/cleanup_seeds.sh
composer install --optimize-autoloader --no-dev
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

## Verification Checklist

- [ ] Composer install completes without warnings
- [ ] No ambiguous class resolution warnings
- [ ] All seeders run successfully
- [ ] Application loads without errors
- [ ] Database connections work
- [ ] All caches are cleared and regenerated
- [ ] File permissions are correct
- [ ] Environment variables are set

## Troubleshooting

### Composer Cache Issues
If composer still can't create cache:
```bash
# Set composer to not use cache
composer config --global cache-dir /tmp/composer-cache
composer install --no-cache
```

### Seeder Issues
If seeders fail:
```bash
# Check seeder files exist
ls -la database/seeders/

# Run individual seeders to identify issues
php artisan db:seed --class=SettingsSeeder
```

### Permission Issues
```bash
# Fix ownership
sudo chown -R www-data:www-data /var/www/seraph3

# Fix permissions
sudo find /var/www/seraph3 -type f -exec chmod 644 {} \;
sudo find /var/www/seraph3 -type d -exec chmod 755 {} \;
sudo chmod -R 775 /var/www/seraph3/storage
sudo chmod -R 775 /var/www/seraph3/bootstrap/cache
``` 