# NXA Lite — Backend Installation (Stage 1)

This stage sets up the database, the connection, and verifies everything works
**before** we build the rest of the API. Follow the steps in order.

Your details (already filled into `config.php`):
- Database: `wxqylcpz_BahaaIsmail`
- MySQL user: `wxqylcpz_BahaaIsmail`
- Site folder: `/home/wxqylcpz/bahaaismail.work`
- PHP: 8.4

---

## Step 1 — Import the database schema

1. cPanel → **phpMyAdmin**.
2. On the left, click your database **`wxqylcpz_BahaaIsmail`**.
3. Top menu → **Import**.
4. **Choose File** → select `schema.sql` → scroll down → **Go**.
5. You should see green success messages and 8 new tables appear on the left
   (brands, categories, families, family_params, products, datasheet_config,
   admin_users, settings).

---

## Step 2 — Upload the files

Upload into your site folder `/home/wxqylcpz/bahaaismail.work` so the result is:

```
bahaaismail.work/
├── uploads/                 (folder, with its .htaccess — keep it)
└── api/
    └── v1/
        ├── config.php
        ├── db.php
        ├── ping.php
        ├── install.php
        └── .htaccess
```

**How (cPanel File Manager):**
1. cPanel → **File Manager** → open `bahaaismail.work`.
2. Use **Upload** to add the files, creating the `api/v1/` and `uploads/`
   folders to match the tree above. (You can upload the provided ZIP and use
   **Extract**.)

---

## Step 3 — Set your database password

1. In File Manager, open `api/v1/config.php` → **Edit**.
2. Find this line:
   ```php
   define('DB_PASS', 'PUT_YOUR_DB_PASSWORD_HERE');
   ```
   Replace `PUT_YOUR_DB_PASSWORD_HERE` with the password you set for the MySQL
   user `wxqylcpz_BahaaIsmail`. Save.
3. (Optional) change `PUBLIC_API_KEY` to any random string.

---

## Step 4 — Verify the connection

Open this URL in your browser:

```
https://bahaaismail.work/api/v1/ping.php
```

Expected result (JSON):
```json
{"ok":true,"data":{"php_version":"8.4.x","db":"connected",
"tables":{...all true...},"admin_count":0,"installed":false,...}}
```

- `"db":"connected"` → the password and connection are correct. ✅
- If you see `"Database connection failed"` → the password in `config.php` is
  wrong, or the user isn't linked to the database. Fix and reload.

> Tip: if you need to see the exact error, set `DEBUG_MODE` to `true` in
> `config.php` temporarily, reload, then set it back to `false`.

---

## Step 5 — Create your super-admin

1. Open:
   ```
   https://bahaaismail.work/api/v1/install.php
   ```
2. Enter your **username** (default `admin`), a **password**, and a **secret
   reset key** (store the reset key somewhere safe — it recovers your password
   without email).
3. Click **Create Super-Admin**. You should see a green success message.
4. **DELETE `install.php`** from the server now (File Manager → select →
   Delete). This is important for security.

---

## Step 6 — Tell me it's done

Reload `ping.php` — it should now show `"admin_count":1` and
`"installed":true`.

When you confirm this, we move to **Stage 2**: the authentication API (login,
reset key, account settings, and multi-admin management), then the catalog,
products, images, and finally wiring the two front-end files to the server.

---

### Notes
- `config.php` and `db.php` are blocked from direct web access by `.htaccess`.
- The `uploads/` folder cannot execute code (safe for images/logos).
- The database starts **empty** — you'll enter all data through the admin panel.
