# 📋 LIVE SERVER UPLOAD CHECKLIST

## Step-by-Step Guide to Fix Your Live Server

---

### ✅ STEP 1: Upload These Files

**Via FTP (FileZilla/WinSCP) or cPanel File Manager:**

| File | Destination | Purpose |
|------|-------------|---------|
| `diagnose.php` | Root directory | Diagnose all issues |
| `test_db_simple.php` | Root directory | Test database connection |
| `index.php` | Root directory | Updated with auto-environment detection |
| `.htaccess` | Root directory | **IMPORTANT: Enable "Show hidden files"!** |
| `fix_permissions.sh` | Root directory (optional) | Auto-fix permissions via SSH |

**⚠️ CRITICAL:** Make sure `.htaccess` uploads! It's hidden by default in FTP clients.

**FileZilla:** Server → Force showing hidden files  
**WinSCP:** Options → Preferences → Panels → Show hidden files

---

### ✅ STEP 2: Fix Permissions

**Option A: Via cPanel Terminal or SSH**

```bash
cd ~/public_html
chmod 777 application/cache
chmod 755 application/logs
chmod 755 uploads/attachments
```

**Option B: Via cPanel File Manager**

1. Right-click `application/cache` → Change Permissions → Set to **777**
2. Right-click `application/logs` → Change Permissions → Set to **755**
3. Right-click `uploads/attachments` → Change Permissions → Set to **755**

**Option C: Run the script**

```bash
bash fix_permissions.sh
```

---

### ✅ STEP 3: Run Diagnostics

**Open in browser (in this order):**

1. **Primary Diagnostic:**
   ```
   https://brandwave.aurigaconsulting.co.in/diagnose.php
   ```
   - Checks PHP version, extensions, permissions, database, files
   - Shows error logs
   - **Action:** Fix anything shown in RED

2. **Database Test:**
   ```
   https://brandwave.aurigaconsulting.co.in/test_db_simple.php
   ```
   - Tests database connection specifically
   - Checks if portal #3 exists
   - **Action:** If fails, see Step 4

3. **Test Login Page:**
   ```
   https://brandwave.aurigaconsulting.co.in/auth/login
   ```
   - Should now load correctly!
   - **Action:** If still 500 error, check diagnose.php output

---

### ✅ STEP 4: If Database Connection Fails

**Option A: Check Firewall/IP Whitelisting**

Your live server IP needs to be whitelisted on database server `162.215.11.244`

Contact your hosting provider to:
- Whitelist the server IP on the database server
- Verify port 3306 is open
- Check database credentials

**Option B: Run SQL Fixes**

If portal #3 doesn't exist in database:

1. Open cPanel → phpMyAdmin
2. Select database: `ac3_marketing_portal`
3. Go to SQL tab
4. Copy and paste commands from `fix_database.sql`
5. Click "Go"

---

### ✅ STEP 5: Verify Everything Works

**Test each URL:**

- [ ] https://brandwave.aurigaconsulting.co.in/ → Should redirect to login
- [ ] https://brandwave.aurigaconsulting.co.in/auth/login → Login page loads
- [ ] https://brandwave.aurigaconsulting.co.in/login → Login page loads (route test)

**Try logging in with test credentials**

---

### ✅ STEP 6: Clean Up Security (AFTER IT WORKS)

**Delete these files from live server:**

```bash
rm diagnose.php
rm test_db_simple.php
rm test_connection.php
rm fix_permissions.sh
rm php_error.log
```

**Or via File Manager:** Delete the files listed above

**Edit index.php** - Comment out error catcher:

Find line 40 and change:
```php
// require_once __DIR__ . '/error_catcher.php';
```

---

## 🔥 MOST COMMON ISSUES & INSTANT FIXES

### Issue #1: 500 Internal Server Error
**Most likely cause:** Cache directory not writable  
**Instant fix:**
```bash
chmod 777 application/cache
```

### Issue #2: 404 on all routes
**Most likely cause:** .htaccess missing  
**Instant fix:** Re-upload .htaccess (enable show hidden files!)

### Issue #3: Database connection failed
**Most likely cause:** Firewall blocking remote database  
**Instant fix:** Contact hosting to whitelist your server IP

### Issue #4: Blank white page
**Most likely cause:** PHP error with display_errors off  
**Instant fix:** Check php_error.log or run diagnose.php

---

## 📊 EXPECTED DIAGNOSE.PHP OUTPUT

### ✅ ALL GREEN (Working):
```
✓ PHP Version: 8.0.x
✓ mysqli extension loaded
✓ mbstring extension loaded
✓ application/logs is writable
✓ application/cache is writable
✓ Database connection successful
✓ Portal ID 3 exists
```

### ❌ ISSUE DETECTED (Needs fixing):
```
✗ application/cache is NOT writable  ← FIX THIS!
✗ Database connection failed         ← FIX THIS!
✗ .htaccess does NOT exist          ← UPLOAD THIS!
```

---

## 🎯 PRIORITY ORDER

1. **FIRST:** Upload diagnose.php → Run it → Read output
2. **SECOND:** Fix permissions (chmod 777 application/cache)
3. **THIRD:** Verify .htaccess uploaded
4. **FOURTH:** Test database connection
5. **FIFTH:** Try /auth/login
6. **SIXTH:** Delete diagnostic files

---

## 💡 PRO TIPS

- **Always check diagnose.php first** - it shows ALL issues at once
- **Cache directory is critical** - 90% of 500 errors are cache permission issues
- **Hidden files matter** - .htaccess MUST be uploaded
- **Test incrementally** - Fix one issue, test, fix next
- **Check server logs** - cPanel → Error Logs for detailed errors
- **PHP version** - Should be 7.4 or 8.0 (not 8.1+)

---

## 📞 NEED HELP?

After running diagnose.php, if still having issues:

1. Screenshot the diagnose.php output
2. Check error logs in cPanel
3. Note any RED error messages
4. Contact your hosting provider with:
   - "Need to whitelist server IP on database 162.215.11.244:3306"
   - "Need application/cache to be writable (777)"
   - "Need mod_rewrite enabled in Apache"

---

## ✨ SUCCESS INDICATORS

You'll know it's working when:
- ✅ diagnose.php shows all green checkmarks
- ✅ https://brandwave.aurigaconsulting.co.in/auth/login loads the login page
- ✅ No 500 Internal Server Error
- ✅ Can attempt login (even if credentials are wrong, page should load)

**If you see the login form, YOU'RE DONE!** 🎉

---

**Start with Step 1 and work through systematically. The diagnostic tools will guide you!**
