# Deploying Abhimanee to cPanel shared hosting

Bringing the current dev database across as-is (existing accounts, products, etc.) — production is not starting empty.

## 1. Requirements
- PHP **8.0 or higher** (cPanel → "Select PHP Version" / "MultiPHP Manager") with extensions: `pdo_mysql`, `mbstring`, `gd` (or `imagick`), `fileinfo`.
- MySQL/MariaDB database.
- `mod_rewrite` enabled (standard on cPanel).

## 2. Upload the files
Everything **except** `.env` (the real one — never upload this, you'll create it fresh on the server), `aaDocument/`, and `.claude/`.

The app's real webroot is `public/` — everything else (`app/`, `core/`, `database/`, `storage/`, etc.) must sit **outside** the publicly-served folder.

- **Preferred**: in cPanel → Domains, set this domain/subdomain's **Document Root** directly to the uploaded project's `public/` subfolder. Upload the whole project one level above that document root (e.g. project in `~/abhimanee/`, document root set to `~/abhimanee/public`).
- **If your host won't let you change the document root** (some very basic shared plans don't): upload the whole project straight into `public_html/`. The root `.htaccess` already included rewrites all requests into `public/` for you — this works, but is slightly less secure than the preferred option since the other folders sit inside the web-accessible tree (they're still individually protected by their own `Require all denied` `.htaccess` files, so this is safe either way, just not the ideal layout).

## 3. Database
1. In cPanel → MySQL Databases, create a new database and a new database user, and add that user to the database with **all privileges**.
2. Open **phpMyAdmin**, select the new (empty) database, go to **Import**, and upload `database/production_import.sql`.
   - This one file contains the full schema **and** current data (all users, products, categories, plans, pricing types, orders, etc. as of go-live) — don't also run `schema.sql`, `seed.sql`, or anything in `migrations/` on top of it, it already includes all of that through migration 020.

## 4. Configure `.env`
Copy `.env.example` to `.env` in the project root (next to `bootstrap.php`, **not** inside `public/`) and fill in real values:

```
APP_ENV=production
APP_DEBUG=false
APP_URL=https://abhimanee.lk
```
(use whichever of abhimanee.lk / abhimanee.com is this deployment's actual domain — no trailing slash)

```
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=<the cPanel database name, usually prefixed like cpaneluser_abhimanee>
DB_USERNAME=<the cPanel database user, similarly prefixed>
DB_PASSWORD=<that user's password>
```

Leave `SESSION_LIFETIME_MINUTES` and the SMS keys as-is unless you have Dialog SMS credentials yet (Phase 2 feature).

**`APP_DEBUG=false` is important** — with it `true`, PHP errors and stack traces become visible to site visitors.

## 5. File permissions
These folders must be writable by the web server user (PHP running as the cPanel account normally already owns everything it creates, but if uploads fail, set these to `755`, or `775` if your host requires group-write):
- `storage/uploads/br`
- `storage/uploads/identity`
- `storage/uploads/slips`
- `public/uploads/products`

## 6. Cron job (background job queue)
In cPanel → Cron Jobs, add a job running **every minute**:
```
* * * * * php /home/<cpanel-username>/<path-to-project>/database/cron_dispatch.php
```
Use the **absolute server path** cPanel shows you when browsing to the file (not a URL). This drains the `jobs` table — nothing depends on it yet in Phase 1, but it's cheap to have running from day one.

## 7. SSL
Enable free SSL (cPanel → SSL/TLS Status → AutoSSL, or Let's Encrypt if offered) for the domain before or right after going live, and make sure `APP_URL` in `.env` uses `https://` once it's active — every link/redirect in the app is built from that one value.

## 8. Smoke test after going live
- Visit the homepage — confirm no PHP errors/warnings show (would indicate `APP_DEBUG` wasn't set to `false`, or a `.env` value is wrong).
- Log in as an existing account (e.g. an SE) and confirm their products/images still show correctly.
- Try the language switcher (EN/SI/TA) and currency toggle (LKR/USD).
- Add a product photo via the SE dashboard — confirms `public/uploads/products` is writable.
- Place a test order through checkout, confirm the payment-slip upload works — confirms `storage/uploads/slips` is writable.
- Confirm `https://abhimanee.lk/.env` and `https://abhimanee.lk/core/Database.php` (or any file outside `public/`) return **403 Forbidden**, not the file contents.
