# 🚀 TastyIgniter Server Commands - Quick Reference

## 📋 DEPLOYMENT COMMANDS (Run Once)

```bash
# Navigate to project
cd ~/public_html/restaurant.minra.top

# Setup environment
cp .env.production.template .env
nano .env  # Add DB password, save (Ctrl+X, Y, Enter)

# Generate app key
php artisan key:generate --force

# Install TastyIgniter (CRITICAL!)
php artisan igniter:install --no-interaction

# Create admin user
php create_admin.php

# Set permissions
chmod -R 755 storage bootstrap/cache public
chmod -R 775 storage bootstrap/cache

# Create storage link
php artisan storage:link

# Optimize for production
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

---

## 🔧 MAINTENANCE COMMANDS

### Clear Caches (when .env or config changes)
```bash
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
```

### Rebuild Caches (for production performance)
```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### View Logs
```bash
# Last 50 lines
tail -50 storage/logs/laravel.log

# Live tail (Ctrl+C to exit)
tail -f storage/logs/laravel.log

# Last 100 lines
tail -100 storage/logs/laravel.log
```

---

## 🗄️ DATABASE COMMANDS

### Test Connection
```bash
php artisan tinker
DB::connection()->getPdo();
# Should show: Pdo\Mysql {#8651 ...}
exit
```

### Count Tables
```bash
php artisan tinker --execute="echo count(DB::select('SHOW TABLES'));"
# Should show: 84
```

### Show All Tables
```bash
php artisan tinker
DB::select('SHOW TABLES');
exit
```

### Check Admin Users
```bash
php artisan tinker
DB::table('ti_admin_users')->get(['username', 'email', 'status']);
exit
```

### Backup Database
```bash
# Manual backup
mysqldump -u minra_tiuser -p minra_tastyigniter > backup_$(date +%Y%m%d).sql

# Or using cPanel
# Navigate to: cPanel → phpMyAdmin → Export
```

---

## 👤 USER MANAGEMENT

### Create Admin User
```bash
php create_admin.php
```

### Change Admin Password
```bash
php artisan igniter:passwd admin@admin.com newpassword123
```

### Check User Count
```bash
php artisan tinker --execute="echo 'Admins: ' . DB::table('ti_admin_users')->count();"
```

---

## 🔄 TASTYIGNITER SPECIFIC

### Fresh Installation (destroys all data!)
```bash
php artisan igniter:down --force
php artisan igniter:install --no-interaction
```

### Update TastyIgniter
```bash
php artisan igniter:update
```

### Discover Extensions
```bash
php artisan igniter:package-discover
```

### List All Igniter Commands
```bash
php artisan list | grep igniter
```

---

## 📊 DIAGNOSTICS

### Check System Status
```bash
php artisan about
```

### Check Database Tables
```bash
php artisan db:table ti_admin_users
php artisan db:table ti_locations
php artisan db:table ti_orders
```

### Test Email Configuration
```bash
php artisan tinker
Mail::raw('Test email', function($msg) {
    $msg->to('your@email.com')->subject('Test');
});
exit
```

### Check PHP Version
```bash
php -v
# Should be 8.3+ or 8.4
```

### Check Composer Version
```bash
composer --version
```

### Check Disk Space
```bash
df -h
du -sh storage/
```

---

## 🛡️ SECURITY COMMANDS

### Check Permissions
```bash
ls -la storage/
ls -la bootstrap/cache/
```

### Fix Permissions
```bash
chmod -R 755 storage bootstrap/cache public
chmod -R 775 storage bootstrap/cache
chown -R minra:minra storage bootstrap/cache
```

### Remove Sensitive Files
```bash
rm create_admin.php
rm .env.example
rm README.md
```

### Check .env Security
```bash
# Verify .env is not web-accessible
curl https://restaurant.minra.top/.env
# Should return 404 or 403, not the file content!
```

---

## 📦 BACKUP & RESTORE

### Full Backup
```bash
# Create backup directory
mkdir -p ~/backups

# Backup files
tar -czf ~/backups/tastyigniter-files-$(date +%Y%m%d).tar.gz \
    -C ~/public_html/restaurant.minra.top .

# Backup database
mysqldump -u minra_tiuser -p minra_tastyigniter \
    > ~/backups/tastyigniter-db-$(date +%Y%m%d).sql

# List backups
ls -lh ~/backups/
```

### Restore from Backup
```bash
# Restore files
cd ~/public_html/restaurant.minra.top
tar -xzf ~/backups/tastyigniter-files-20260702.tar.gz

# Restore database
mysql -u minra_tiuser -p minra_tastyigniter \
    < ~/backups/tastyigniter-db-20260702.sql

# Clear caches
php artisan config:clear
php artisan cache:clear
```

---

## 🐛 TROUBLESHOOTING

### "Database connection required"
```bash
# Check .env
cat .env | grep DB_

# Test connection
php artisan tinker --execute="DB::connection()->getPdo();"
```

### "Only 5 tables exist"
```bash
# Reinstall TastyIgniter
php artisan igniter:down --force
php artisan igniter:install --no-interaction
```

### "Column 'username' not found"
```bash
# Tables have wrong schema, reinstall
php artisan igniter:down --force
php artisan igniter:install --no-interaction
```

### "Access denied for user"
```bash
# Check username
cat .env | grep DB_USERNAME
# Should be: minra_tiuser (not minra_user!)

# Fix if wrong
nano .env
php artisan config:clear
```

### "Class not found"
```bash
# Rebuild autoloader
composer dump-autoload --optimize

# Or reinstall dependencies
composer install --no-dev --optimize-autoloader
```

### "Permission denied"
```bash
# Fix permissions
chmod -R 775 storage bootstrap/cache
chown -R minra:minra storage bootstrap/cache
```

---

## 🔄 RESET COMMANDS (USE WITH CAUTION!)

### Clear Everything (Development Only!)
```bash
php artisan igniter:down --force
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
rm -rf bootstrap/cache/*.php
```

### Fresh Start (Destroys All Data!)
```bash
# Backup first!
php artisan igniter:down --force
rm -rf storage/app/public/*
rm -rf storage/logs/*.log
php artisan igniter:install --no-interaction
php create_admin.php
```

---

## 📞 SUPPORT CHECKS

### System Info for Support
```bash
echo "=== SYSTEM INFO ==="
echo "PHP Version: $(php -v | head -1)"
echo "Table Count: $(php artisan tinker --execute='echo count(DB::select(\"SHOW TABLES\"));' 2>/dev/null)"
echo "Disk Usage: $(du -sh . | cut -f1)"
echo "Last Error:"
tail -3 storage/logs/laravel.log
```

### Database Health Check
```bash
php artisan tinker
echo "=== DATABASE HEALTH ===";
echo "Tables: " . count(DB::select('SHOW TABLES'));
echo "Admins: " . DB::table('ti_admin_users')->count();
echo "Locations: " . DB::table('ti_locations')->count();
echo "Orders: " . DB::table('ti_orders')->count();
exit
```

---

## ⚡ ONE-LINE COMMANDS

```bash
# Deploy from scratch
cp .env.production.template .env && nano .env && php artisan key:generate --force && php artisan igniter:install --no-interaction && php create_admin.php && php artisan config:cache

# Clear all caches
php artisan config:clear && php artisan cache:clear && php artisan route:clear && php artisan view:clear

# Rebuild all caches
php artisan config:cache && php artisan route:cache && php artisan view:cache

# Full backup
tar -czf ~/backup-$(date +%Y%m%d).tar.gz . && mysqldump -u minra_tiuser -p minra_tastyigniter > ~/backup-db-$(date +%Y%m%d).sql

# Check system health
php -v && php artisan tinker --execute="echo 'Tables: ' . count(DB::select('SHOW TABLES'));"
```

---

## 🎯 MOST USED COMMANDS

```bash
# Daily
tail -f storage/logs/laravel.log

# Weekly
php artisan cache:clear && php artisan config:cache

# After .env changes
php artisan config:clear && php artisan config:cache

# After code updates
composer dump-autoload && php artisan config:cache && php artisan route:cache

# Emergency fix
php artisan igniter:down --force && php artisan igniter:install --no-interaction
```

---

**Keep this file handy for quick reference!**
