# 🚀 ZIPO Backend — Namecheap Go-Live Guide

This package is **ready to upload and go live** on Namecheap shared hosting (cPanel).

## ✅ Already Done (No need to repeat)
- **Database created** on Namecheap: `ofrijqsq_zipo_database`
- **DB user**: `ofrijqsq_zipo_system`
- **DB password**: `zipometer2026`
- **SQL schema imported** into the database (all tables + admin user + seed data)
- **Production `.env`** already embedded inside `laravel-backend-deploy.zip` with the above credentials & a fresh APP_KEY.
- **Domain**: `tijofriq.store` (APP_URL already set to `https://tijofriq.store`)

> 🎉 So there's **NO** manual `.env` editing, **NO** database import, and **NO** `php artisan key:generate` needed.
> Just upload, extract, set permissions, and go live.

---

## QUICK STEPS (What YOU do now)

### 1. Upload & Extract the zip
- cPanel → **File Manager** → go into **`public_html`**
- Click **Upload** → select `laravel-backend-deploy.zip`
- Once uploaded, right-click the zip → **Extract**
- Result: a `laravel-backend/` folder is created inside `public_html/`

### 2. Set permissions
- In File Manager, select these folders and set **Permissions** to **755**:
  - `public_html/laravel-backend/storage`
  - `public_html/laravel-backend/storage/framework`
  - `public_html/laravel-backend/storage/logs`
  - `public_html/laravel-backend/bootstrap/cache`
- (Optional 775 if 755 gives permission errors)

### 3. Set PHP version to 8.3+
- cPanel → **Select PHP Version**
- Choose **PHP 8.3** (or 8.4)
- Enable these PHP extensions (tick the boxes):
  `bcmath`, `ctype`, `curl`, `dom`, `fileinfo`, `gd`, `mbstring`, `openssl`, `pdo_mysql`, `xml`, `tokenizer`

### 4. Serve the app (Choose ONE)

#### 🅰️ Option A — Subdomain (recommended, clean URL)
- cPanel → **Subdomains**
- Create subdomain: `api`
- Set document root to: `public_html/laravel-backend/public`
- Your API base becomes: `https://api.yourdomain.com/api`

#### 🅱️ Option B — Folder path (simplest)
- Keep the app in `public_html/laravel-backend/`
- Your API base becomes: `https://yourdomain.com/laravel-backend/public/api`

---

## ⚙️ Post-upload commands (in cPanel → Terminal, if available)

These make the app faster & fully initialised. If you don't have Terminal, the app still works — just skip to step 5.

```bash
cd ~/public_html/laravel-backend

# Clear any cached config
php artisan config:clear
php artisan cache:clear
php artisan view:clear

# Re-cache for production speed
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Create symlink so profile photos are served
php artisan storage:link

# Verify DB connection works
php artisan migrate:status
```

> ⚠️ If `config:cache` or `route:cache` fails (common on shared hosting), it's usually a permissions issue on `storage/` or `bootstrap/cache/`. Re-check step 2. You can also just run `config:clear` and leave it uncached — the app works fine.

---

## 🔐 App key (already set)
Your `.env` already contains a valid `APP_KEY`. **Do not** run `key:generate` again or existing tokens/hashes will be invalidated.

---

## 📱 Point your Flutter apps

Update the base URL in your Flutter `api_service.dart`/config to match your option in Step 4:

- **Option A**: `https://api.yourdomain.com/api`
- **Option B**: `https://yourdomain.com/laravel-backend/public/api`

---

## 🧪 Test login
- **Email:** `admin@zipo.com`
- **Password:** `password123`
- Endpoint: `POST {baseUrl}/auth/login`

Expected response:
```json
{
  "success": true,
  "message": "Login successful",
  "user": { ... },
  "token": "..."
}
```

---

## ❗ Troubleshooting
| Problem | Fix |
|--------|-----|
| 403 / File not found | Check `public/.htaccess` is present, document root points to `.../public` |
| 500 Error | Check `storage/logs/laravel.log`; fix `storage` & `bootstrap/cache` permissions |
| DB connection error | Confirm `.env` DB values; confirm user has ALL PRIVILEGES on the DB |
| Blank page | Run `php artisan config:clear` in Terminal |
| Login fails | Verify SQL import ran fully; re-run import if needed |

---
**Default Admin Credentials:** `admin@zipo.com` / `password123`

