# PAL Procurement — cPanel Deployment Guide

This package is **ready to run — no Composer, no `artisan`, no build step required.**
The `vendor/` folder and the pre-built front-end assets (`public/build`) are already included.

**Package contents**
```
pal-app/                     The complete Laravel 12 application (vendor/ included)
database_export/
    pal_procurement.sql      Full database dump (schema + data, 45 tables)
DEPLOY_CPANEL.md             This guide
```

Requirements on the server: **PHP 8.2+** and **MySQL/MariaDB**.

---

## 1. Create and import the database

1. In cPanel → **MySQL® Databases**, create a database and a user, and **add the user to the database with ALL PRIVILEGES**.
   (cPanel prefixes names, so you'll get something like `myacct_pal` and `myacct_paluser`.)
2. In cPanel → **phpMyAdmin**, select the new database → **Import** → choose
   `database_export/pal_procurement.sql` → **Go**.
   The 45 tables and all data (formation tree, users, reference data) will load.

## 2. Upload the application

Upload the `pal-app` folder to your account and extract it. Two common layouts:

**A. Subdomain / addon domain (recommended, cleanest URLs)**
- Put `pal-app` anywhere (e.g. `/home/myacct/pal-app`).
- Create a subdomain (e.g. `pal.yourdomain.com`) and set its **Document Root** to
  `/home/myacct/pal-app/public`.

**B. Inside your main site (no docroot change)**
- Upload so you have `public_html/pal-app/…`.
- The app will then be served at `https://yourdomain.com/pal-app/public`.
  (A subdomain pointed at `/pal-app/public` is still nicer — use A if you can.)

## 3. Configure the environment

1. In `pal-app`, rename **`.env.cpanel` → `.env`**.
2. Edit `.env` and set:
   - `APP_URL=` your real URL (e.g. `https://pal.yourdomain.com`)
   - `DB_DATABASE=`, `DB_USERNAME=`, `DB_PASSWORD=` from step 1.
   - (Optional) mail settings if you want e-mail notifications to send.
   - Leave `APP_KEY` as-is (already set), `APP_ENV=production`, `APP_DEBUG=false`.

## 4. Permissions

Make these writable by the web server (cPanel File Manager → Permissions, or Terminal):
```
chmod -R 775 pal-app/storage
chmod -R 775 pal-app/bootstrap/cache
```

## 5. Link the uploads folder (documents/attachments)

Uploaded documents live in `storage/app/public` and are served from `public/storage`.
Create that link **once**, using whichever works on your host:

- **Easiest:** visit `https://YOUR-URL/link-storage.php` in a browser. It should say
  *"Storage linked successfully"*. Then **delete `public/link-storage.php`**.
- **Or** in cPanel → Terminal:
  ```
  cd pal-app/public && ln -s ../storage/app/public storage
  ```

## 6. Done — log in

Open your `APP_URL`. Seeded logins (password for all: **`password`**):

| Role              | Email               |
|-------------------|---------------------|
| Administrator     | admin@pal.test      |
| PAL               | pal@pal.test        |
| Procurement       | procurement@pal.test|
| Area              | area@pal.test       |
| Budget / Finance  | finance@pal.test    |
| Station           | station@pal.test    |

> **Security:** change these passwords immediately (Admin → Users), and set real e-mail
> addresses. Delete `public/link-storage.php` after use.

---

## Notes & troubleshooting

- **No Composer/artisan needed.** Everything is bundled. If you later change `.env`, just
  reload the page — nothing is cached (caches were cleared before packaging).
- **500 error / blank page:** check `pal-app/storage/logs/laravel.log`. Usual causes:
  wrong DB credentials in `.env`, or `storage/` not writable (step 4).
- **PHP version:** must be 8.2 or newer (cPanel → *MultiPHP Manager* / *Select PHP Version*).
  Ensure common extensions are on: `pdo_mysql`, `mbstring`, `openssl`, `fileinfo`, `gd`, `zip`.
- **"419 / page expired" on login:** confirm `APP_URL` matches the address you're visiting
  (http vs https, with/without `www`).
- **Scheduled overdue-escalation** (optional): add a cron job in cPanel →
  `php /home/myacct/pal-app/artisan schedule:run` every minute. Not required for core use.
