# XAMPP Quickstart

This zip is a **complete, ready-to-run CodeIgniter 4 install** — framework,
vendor/ dependencies, and all custom modules (Auth, Users, Roles &
Permissions) already in place. No `composer install` needed.

Pre-configured for: **http://localhost/enterprise/**

## 1. Place it in htdocs

Extract this zip so its contents land directly at:

- Windows: `C:\xampp\htdocs\enterprise\`
- macOS/Linux: `/Applications/XAMPP/htdocs/enterprise/` or `/opt/lampp/htdocs/enterprise/`

You should see `C:\xampp\htdocs\enterprise\app`, `...\enterprise\public`,
`...\enterprise\.htaccess`, etc. — not an extra nested folder.

## 2. Start Apache and MySQL in the XAMPP Control Panel

## 3. Create the database

Open **phpMyAdmin** (`http://localhost/phpmyadmin`) and create a database
named exactly:

```
erp_foundation
```

(Or via the MySQL console: `CREATE DATABASE erp_foundation CHARACTER SET utf8mb4;`)

The app is already configured for XAMPP's MySQL defaults — user `root`,
no password. If your XAMPP MySQL has a root password set, edit `.env`:

```
database.default.username = root
database.default.password = your_password_here
```

## 4. Run migrations and seed the database — no CLI needed

**Some XAMPP installs have a broken or non-standard CLI `php.exe`** (wrong
`extension_dir` in `php.ini`, missing DLLs, custom folder layout, etc.)
even though the browser works fine. So this package includes a **one-time
browser-based installer** that uses the exact same PHP that's already
serving your pages — no command line required.

1. Open `.env` in the project folder and find this line near the bottom:
   ```
   INSTALL_TOKEN = e9dcb1473787453fc897fcaad5aa1078
   ```
   (Yours will have a different random value — that's fine, use whatever's there.)

2. Visit, in your browser:
   ```
   http://localhost/enterprise/install?token=e9dcb1473787453fc897fcaad5aa1078
   ```
   (replacing the token with the one from your `.env`)

3. Click **"Yes, run migrations & seed now"**.

4. You'll see a confirmation page with a **one-time temporary admin
   password** — copy it immediately, it will not be shown again.

That's it — migrations and seeding are done. The installer refuses to run
a second time once it's succeeded (delete `writable/install.lock` if you
genuinely need to re-run it).

### Prefer the command line? It still works if your CLI PHP is healthy:

```bash
# Windows example:
C:\xampp\php\php.exe spark migrate --all
C:\xampp\php\php.exe spark db:seed DatabaseSeeder

# macOS/Linux example:
/Applications/XAMPP/bin/php spark migrate --all
/Applications/XAMPP/bin/php spark db:seed DatabaseSeeder
```
Run these from **inside the `enterprise` folder** (`cd` there first), and
type/paste **one command at a time**, pressing Enter and waiting for it to
finish before the next — pasting multiple lines at once can concatenate
them into one broken command on Windows.

If you get "system cannot find the path" or extension-loading warnings,
your `php.exe` path or `php.ini`'s `extension_dir` doesn't match your
actual XAMPP layout — the browser installer above sidesteps this
entirely, so it's the easier path on a fussy setup.

## 5. Log in

Visit **http://localhost/enterprise/login** and sign in with:

- Username: `admin`
- Password: *(whatever the installer/seeder printed in step 4)*

You'll be forced to set a new password on first login.

## 6. Clean up the installer (recommended once you're done)

Delete `app/Controllers/Install.php` and remove the `install` route line
from `app/Config/Routes.php`, or at minimum remove `INSTALL_TOKEN` from
`.env` — the lock file already blocks it from running again, but there's
no reason to leave the endpoint reachable.

## Already verified working

This exact package was tested end-to-end in a real Apache + MySQL
environment (mirroring XAMPP) before being zipped: migrations run clean,
the browser installer seeds the database and prints a working temp
password, `/login` authenticates that password and redirects correctly,
and `/users` and `/roles` load for the authenticated admin — all through
the `http://localhost/enterprise/...` URL structure with the `.htaccess`
rewrite from the project root into `public/`.

## If you get a blank page or 500 error

1. Check `writable/logs/` for the actual error (create the folder with
   write permission if it's missing — XAMPP sometimes strips permissions
   on zip extraction).
2. Confirm `mod_rewrite` is enabled in XAMPP's Apache (`httpd.conf` →
   uncomment `LoadModule rewrite_module modules/mod_rewrite.so`) and that
   `AllowOverride All` is set for `htdocs` (also in `httpd.conf`) — both
   are XAMPP defaults, but double-check if you've customized your install.
3. Confirm the database name/credentials in `.env` match what you created
   in phpMyAdmin.

## What's next

See `docs/01-authentication.md`, `docs/02-user-management.md`, and
`docs/03-roles-permissions.md` for what each module does, its security
notes, and a manual test checklist. `README.md` has the full build-order
roadmap for the remaining 9 modules.
