# 🚀 Deploy TastyIgniter to restaurant.minra.top

## ✅ LOCAL INSTALLATION COMPLETE!

Your local TastyIgniter is running at: **http://127.0.0.1:8000**

- **Admin Login**: http://127.0.0.1:8000/admin
- **Username**: `admin`
- **Password**: `admin123`
- **Database**: `tastyigniter_local` (84 tables created)

---

## 📦 DEPLOYMENT STEPS

### Step 1: Create Production .env File

Create a new file: `.env.production` with these settings:

```env
# APPLICATION SETTINGS
APP_NAME="Restaurant POS"
APP_ENV=production
APP_KEY=base64:YOUR_PRODUCTION_KEY_HERE
APP_DEBUG=false
APP_URL=https://restaurant.minra.top

IGNITER_CARTE_KEY=
IGNITER_LOCATION_MODE=multiple

# DATABASE CONFIGURATION
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=minra_tastyigniter
DB_USERNAME=minra_tiuser
DB_PASSWORD=YOUR_DATABASE_PASSWORD
DB_PREFIX=

# CACHE & SESSION
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

# MAIL CONFIGURATION
MAIL_MAILER=smtp
MAIL_HOST=mail.minra.top
MAIL_PORT=587
MAIL_USERNAME=noreply@minra.top
MAIL_PASSWORD=YOUR_EMAIL_PASSWORD
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@minra.top
MAIL_FROM_NAME="${APP_NAME}"
```

**IMPORTANT**: 
- Generate a new `APP_KEY` on the server: `php artisan key:generate`
- Replace `YOUR_DATABASE_PASSWORD` with the actual password
- **NEVER USE `DB_PREFIX=ti_`** - TastyIgniter already adds `ti_` prefix automatically!

---

### Step 2: Prepare Deployment Package

Option A: **Direct Upload via cPanel File Manager**

1. ZIP the entire `TastyIgniter-New` folder
2. Upload to `/home/minra/public_html/restaurant.minra.top/`
3. Extract on server
4. Delete the ZIP file

Option B: **Use SSH/SCP**

```bash
# From your local machine
scp -r c:\laragon\www\TastyIgniter-New minra@server:~/public_html/restaurant.minra.top/
```

---

### Step 3: Server Configuration (SSH Required)

**Login to your server**:
```bash
ssh minra@server
cd ~/public_html/restaurant.minra.top
```

**3.1. Copy production environment file**:
```bash
cp .env.production .env
# Edit .env and add your database password
nano .env
```

**3.2. Generate application key**:
```bash
php artisan key:generate --force
```

**3.3. Set permissions**:
```bash
chmod -R 755 storage bootstrap/cache public
chmod -R 775 storage bootstrap/cache
```

**3.4. Create symbolic link for storage**:
```bash
php artisan storage:link
```

**3.5. Clear all caches**:
```bash
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
```

---

### Step 4: DATABASE SETUP (CRITICAL!)

**4.1. Drop existing tables** (if you deployed before):
```bash
php artisan igniter:down --force
```

**4.2. Run TastyIgniter installation**:
```bash
php artisan igniter:install --no-interaction
```

This will:
- Create **84 database tables** (not just 5!)
- Set up all TastyIgniter extensions
- Configure the system
- Publish theme assets

**4.3. Verify tables created**:
```bash
php artisan tinker
DB::select('SHOW TABLES');
# Should show 84 tables, not 5!
exit
```

**4.4. Create admin user**:
```bash
# Upload the create_admin.php script to server
php create_admin.php
```

Or create manually:
```bash
php artisan tinker
DB::table('ti_admin_users')->insert([
    'username' => 'admin',
    'name' => 'Admin User',
    'email' => 'admin@admin.com',
    'password' => Hash::make('admin123'),
    'super_user' => 1,
    'status' => 1,
    'is_activated' => 1,
    'activated_at' => now(),
    'created_at' => now(),
    'updated_at' => now(),
]);
exit
```

---

### Step 5: Optimize for Production

```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

---

### Step 6: Test the Installation

1. Visit: **https://restaurant.minra.top/admin/login**
2. Login with:
   - **Username**: `admin`
   - **Password**: `admin123`
3. Should see the TastyIgniter admin dashboard!

---

## 🔍 TROUBLESHOOTING

### Problem: "Database Connection Required" Error

**Solution**:
```bash
# Test database connection
php artisan tinker
DB::connection()->getPdo();
# Should return PDO object, not error
exit

# If error, check .env file:
nano .env
# Verify DB_USERNAME, DB_PASSWORD, DB_DATABASE are correct
# IMPORTANT: Ensure DB_PREFIX= is EMPTY (no ti_)
```

### Problem: Only 5 Tables Created

**Solution**:
You ran `php artisan migrate` instead of `php artisan igniter:install`. Fix it:
```bash
php artisan igniter:down --force
php artisan igniter:install --no-interaction
```

### Problem: "Column 'username' not found"

**Solution**:
Tables have wrong schema. You need to run `igniter:install`:
```bash
php artisan igniter:down --force
php artisan igniter:install --no-interaction
```

### Problem: "Access denied for user 'minra_user'"

**Solution**:
Wrong username in `.env`. Should be `minra_tiuser`, not `minra_user`:
```bash
nano .env
# Change: DB_USERNAME=minra_tiuser
php artisan config:clear
```

### Problem: Double Prefix `ti_ti_admin_users`

**Solution**:
Remove prefix from `.env`:
```bash
nano .env
# Change: DB_PREFIX= (leave empty!)
php artisan config:clear
```

---

## 📋 QUICK DEPLOYMENT CHECKLIST

- [ ] Created `.env.production` with correct database credentials
- [ ] Uploaded all files to server
- [ ] Set file permissions (755/775)
- [ ] Copied `.env.production` to `.env`
- [ ] Generated APP_KEY: `php artisan key:generate --force`
- [ ] Verified DB_PREFIX is EMPTY in `.env`
- [ ] Ran `php artisan igniter:install --no-interaction`
- [ ] Verified 84 tables created (not 5!)
- [ ] Created admin user
- [ ] Cached config: `php artisan config:cache`
- [ ] Tested login at `/admin/login`

---

## 🎯 DEPLOYMENT TIME ESTIMATE

- **File Upload**: 5-10 minutes (depends on internet speed)
- **Server Configuration**: 5 minutes
- **Database Setup**: 2-3 minutes
- **Testing**: 2 minutes

**Total**: ~15-20 minutes

---

## 📞 SUPPORT

If you encounter issues:

1. Check error logs:
   ```bash
   tail -f storage/logs/laravel.log
   ```

2. Test database connection:
   ```bash
   php artisan tinker
   DB::connection()->getPdo();
   ```

3. Verify table count:
   ```bash
   php artisan tinker
   echo count(DB::select('SHOW TABLES'));
   # Should be 84
   ```

---

## 🔒 SECURITY NOTES

After deployment:

1. **Change default admin password**
2. **Remove `create_admin.php` script**:
   ```bash
   rm create_admin.php
   ```
3. **Disable debug mode** (ensure `APP_DEBUG=false` in `.env`)
4. **Set up SSL** (cPanel AutoSSL should handle this)
5. **Regular backups**:
   ```bash
   # Backup database
   php artisan db:backup
   
   # Backup files
   tar -czf tastyigniter-backup-$(date +%Y%m%d).tar.gz .
   ```

---

## ✨ NEXT STEPS AFTER DEPLOYMENT

1. Configure your restaurant details in Settings
2. Add menu items, categories, and prices
3. Set up delivery zones and working hours
4. Configure payment gateways (Stripe, PayPal, etc.)
5. Customize theme and branding
6. Test ordering workflow
7. Train staff on the system

---

**Good luck with your deployment!** 🚀
