# Running TrustFund on XAMPP (your own computer)

This runs the whole system on your own machine with XAMPP's MySQL (MariaDB) database. Nobody else can reach it, so it is
for testing, demos and development. Written for Windows; on macOS replace `C:\xampp` with `/Applications/XAMPP/xamppfiles`.

**You need:** XAMPP with PHP 8.1 or newer (any recent download of XAMPP has it).

## 1. Put the project in the right place

Unzip `trustfund.zip` into **`C:\xampp\trustfund`** so that `C:\xampp\trustfund\public\index.php` exists.

> Do **not** put it inside `C:\xampp\htdocs`. The app expects its own web address (for example `http://localhost:8080`)
> and keeps its code, settings and uploaded evidence outside the public folder.

## 2. Start MySQL and create the database

1. Open the **XAMPP Control Panel** and click **Start** next to **MySQL**. (Start Apache too only if you choose option B below.)
2. Open <http://localhost/phpmyadmin> in your browser (this needs Apache running; otherwise use the MySQL **Shell** button instead).
3. Click **New**, type the name **`trustfund`**, choose collation **`utf8mb4_unicode_ci`**, click **Create**.

## 3. Tell the app how to reach the database

In `C:\xampp\trustfund`, copy `config.local.xampp.example.php` to a new file named **`config.local.php`**.
Its defaults match a fresh XAMPP (user `root`, empty password), so you normally change nothing.

## 4. Create the tables

In the XAMPP Control Panel click **Shell** (or open Command Prompt) and run:

```
cd C:\xampp\trustfund
php bin\install.php --demo
```

This creates the tables plus four demo accounts and one live demo campaign. All demo accounts use the password `Demo#12345`:
`admin@example.com`, `auditor@example.com`, `recipient@example.com`, `donor@example.com`.

Want your own admin and no demo data instead?
`php bin\install.php --admin-name="Your Name" --admin-email=you@example.com --admin-password="A-Long-Passphrase"`

If you see `WARNING: Could not create ledger_no_update trigger`, tell me the full message. The app still works, and the
hash-chain integrity check still catches tampering, but the extra database lock on the ledger would be missing.

## 5. Start the website (pick one)

**Option A: easiest, no Apache needed.** Double-click **`run-xampp.bat`** in the project folder (or run
`C:\xampp\php\php.exe -S localhost:8080 -t public` from `C:\xampp\trustfund`). Leave that window open, then browse to
**<http://localhost:8080>**. Close the window to stop the site.

**Option B: let Apache serve it.**
1. Open `C:\xampp\apache\conf\extra\httpd-vhosts.conf` in a text editor and add this at the bottom:
   ```apache
   Listen 8080
   <VirtualHost *:8080>
       DocumentRoot "C:/xampp/trustfund/public"
       <Directory "C:/xampp/trustfund/public">
           Require all granted
           DirectoryIndex index.php
           FallbackResource /index.php
       </Directory>
   </VirtualHost>
   ```
2. In the Control Panel, **Stop** then **Start** Apache.
3. Browse to **<http://localhost:8080>**.

## 6. Try the whole flow (about 5 minutes)

Use a normal window plus a private (incognito) window so you can be two people at once.

1. Log in as **donor@example.com**, open the demo campaign, donate RM 4,000. Stage 1 turns to "Funds released".
2. Log in as **recipient@example.com** (private window), open the campaign, click **Report spending**, attach any JPG, PNG or PDF.
3. Log in as **auditor@example.com**, open **Audit queue**, review it, and approve.
4. As the donor, donate RM 3,000 more. Stage 2 is now released. Repeat for stage 3 and watch the campaign close.
5. Open **Ledger** on the campaign. It should say "Integrity check passed".
6. As **admin@example.com**, look at the dashboard, users, activity log, and try freezing a campaign.

## Where things are stored

| What | Where |
| --- | --- |
| Data | MySQL database `trustfund` (see it in phpMyAdmin) |
| Uploaded evidence and documents | `C:\xampp\trustfund\storage\uploads` |
| "Sent" emails (nothing is really emailed on XAMPP) | `C:\xampp\trustfund\storage\mail.log` |

To start again from scratch: in phpMyAdmin drop the `trustfund` database, create it again, and rerun step 4.

## Troubleshooting

| Problem | Fix |
| --- | --- |
| `could not find driver` | In `C:\xampp\php\php.ini` make sure the line `extension=pdo_mysql` has no `;` in front, then restart the site |
| `Access denied for user` or `Unknown database` | Check the name, user and password in `config.local.php`, and that the database `trustfund` exists |
| `Connection refused` | MySQL is not started in the XAMPP Control Panel, or something else is using port 3306 |
| Every page except the home page shows "not found" (option B) | Check the `FallbackResource` line and restart Apache |
| "Only JPG, PNG or PDF files are allowed" for a valid file | In `php.ini` make sure `extension=fileinfo` has no `;` in front, then restart |
| A page says "Something went wrong" | Set `'debug' => true` in `config.local.php` to see the real error, then set it back to `false` |

## When you are ready for the real thing

XAMPP on your own computer is not safe or practical for the public (it is only reachable from your machine, and only while it is on).
For real donors you need online hosting. `DEPLOY.md` covers DigitalOcean, and the same app also runs on any host that gives you
PHP 8.1+ and MySQL; point the web root at the `public` folder. Everything else you test here carries over unchanged.
