# 🚀 ZIPO — InfinityFree Go-Live Guide

Your package is **fully configured** for InfinityFree. No `.env` editing needed.

## ✅ Package ready
File: **`laravel-backend-infinityfree.zip`**

Already configured inside:
- **APP_URL**: `https://ziposystem.great-site.net`
- **DB_HOST**: `sql306.infinityfree.com`
- **DB_DATABASE**: `if0_42599145_ziposystem_db`
- **DB_USERNAME**: `if0_42599145`
- **DB_PASSWORD**: `P6SQ5eip3wErwrB`
- **APP_KEY**: fresh, valid (do NOT run key:generate)

---

## STEP 1 — Import the database (if not done)

1. Log into **InfinityFree** → **Control Panel**
2. Go to **MySQL Databases** → confirm your DB `if0_42599145_ziposystem_db` exists
3. Open **phpMyAdmin** for that database
4. Click **Import** tab
5. Choose the file: `database/zipo_database.sql`
   - ⚠️ If the import errors on the first lines, that's fine — the SQL has `CREATE DATABASE/USE` commented out already, so it imports into the currently selected DB.
6. Click **Go** / **Import**
7. Confirm you see tables: `users`, `properties`, `units`, `meters`, `meter_readings`, `transactions`, `wallets`, `alerts`, `support_tickets`, `system_configs`, `disconnection_logs`, `rent_schedules`, `rent_invoices`, `personal_access_tokens`, `migrations`, `sessions`, `cache`, `jobs`, etc.

---

## STEP 2 — Set PHP version to 8.3+

Your app runs **Laravel 13**, which requires **PHP 8.3 or higher** (check `composer.json`: `"php": "^8.3"`). If the server runs an older PHP (e.g. 8.0/8.1/8.2), the app will show a **blank page or 500 error**. So this step is critical.

### 2a. Where to find the setting

1. Log into **InfinityFree** → **Control Panel**
2. In the left sidebar, look for **"Tools"** section
3. Click **"PHP Version"** — OR look for a **gear/global icon** labeled **"PHP Version"** near the top of the dashboard
   - If you can't find it, look under **"Advanced"** → **"PHP Version"**

### 2b. Select the PHP version

- From the dropdown, select the **highest available** version.
- **PHP 8.3** is ideal. **PHP 8.4** also works.
- If you see **PHP 8.2 or lower only**, the app will NOT run — contact me and I'll guide you (or use the Namecheap host instead, which has 8.3+).

> ℹ️ InfinityFree allows you to change the PHP version per subdomain/domain. Make sure you apply the change to **`ziposystem.great-site.net`** (the domain you'll use for the app), not a different one.

### 2c. Enable required PHP extensions

After selecting the version, you'll see a list of **tick-boxes** for extensions. **Enable these** (tick them on):

| Extension | Why it's needed |
|-----------|----------------|
| `pdo_mysql` | 🔑 **Critical** — connects Laravel to your MySQL database |
| `mysqli` | Backup DB driver (used by phpMyAdmin too) |
| `mbstring` | Text/UTF-8 handling for names, emails, descriptions |
| `openssl` | 🔑 **Critical** — encryption for passwords, tokens, APP_KEY, HTTPS |
| `curl` | 🔑 **Critical** — used for Flutterwave payment API calls |
| `tokenizer` | Required by Laravel internals |
| `xml` / `dom` | Parsing XML (used by some packages) |
| `ctype` | Validation helper used by Laravel |
| `json` | JSON encoding/decoding for all API responses |
| `fileinfo` | Detects file types (used for photo uploads) |
| `bcmath` | Precise decimal math (used for money/balances) |
| `gd` | Image processing for profile photo uploads |
| `zip` | Only needed if you run composer on the server (you won't) |
| `exif` | Optional — photo metadata |

> ✅ If some of these are already ticked, leave them. If an extension isn't listed, don't worry — InfinityFree usually has the common ones pre-enabled.

### 2d. Save & verify

1. Click **Save** / **Update**
2. To confirm the PHP version took effect, open this URL in your browser **after** you finish uploading in Step 3:

   ```
   https://ziposystem.great-site.net/laravel-backend/public/phpinfo.php
   ```

   You should see a big PHP information table. At the top, check the **"PHP Version"** line — it must show **8.3.x or 8.4.x**.

> 💡 If that page shows a 403/404, your files aren't uploaded yet — come back to it after Step 3.

---

## STEP 3 — Upload the zip to `htdocs`

Your web root on InfinityFree is **`htdocs`** (not `public_html`).

### Option A — File Manager (if zip is small enough)
1. InfinityFree control panel → **File Manager**
2. Go into **`htdocs`**
3. Upload `laravel-backend-infinityfree.zip`
4. Right-click → **Extract**
5. Result: `htdocs/laravel-backend/`

### Option B — FTP (recommended, zip is large)
1. Download **FileZilla** (free)
2. Connect with your InfinityFree FTP details (from control panel → FTP Details):
   - Host: `ftp.ziposystem.great-site.net`
   - Username: `if0_42599145`
   - Password: your account password
3. Upload `laravel-backend-infinityfree.zip` into `/htdocs/`
4. After upload, use File Manager → **Extract**

---

## STEP 4 — Set folder permissions

InfinityFree default permissions (755) are usually fine. If you get errors:
- Select `htdocs/laravel-backend/storage` → **Permissions** → **755** (or 775)
- Select `htdocs/laravel-backend/bootstrap/cache` → **755** (or 775)

---

## STEP 5 — Test your live API

Open in your browser:

```
https://ziposystem.great-site.net/laravel-backend/public/api/system-config
```

**Expected:** JSON data (config values like `tax_percentage`, `unit_price_per_kwh`).

If you see JSON → **your app is LIVE!** 🎉

---

## STEP 6 — Point your Flutter apps

Update your Flutter `api_service.dart`:

```dart
String baseUrl = 'https://ziposystem.great-site.net/laravel-backend/public/api';
```

Then test login:
- **Email:** `admin@zipo.com`
- **Password:** `password123`
- Endpoint: `POST {baseUrl}/auth/login`

---

## ❗ Troubleshooting

| Problem | Fix |
|--------|-----|
| 500 Error | Open `htdocs/laravel-backend/storage/logs/laravel.log` and check the error; usually permissions or PHP version |
| DB connection error | Confirm `.env` inside `htdocs/laravel-backend/.env` has the right DB values; confirm the SQL imported |
| Blank page | Check PHP version is 8.3+; check storage permissions |
| Login fails | Re-import the SQL; confirm `users` table has `admin@zipo.com` |
| 404 on /public | Make sure files are at `htdocs/laravel-backend/public/` (contains `index.php`) |

---

**Default Admin:** `admin@zipo.com` / `password123`

