# Winery POS — cPanel Production Installation Guide

**Production Domain:** `https://winery.danskictmanagement.com`  
**Currency / Timezone:** `UGX` / `Africa/Kampala`  
**Database:** MySQL 8.0+ / MariaDB 10.6+

---

## 1. Create the Subdomain in cPanel
1. Log in to **cPanel** and open **Domains** (or **Subdomains**).
2. Create the subdomain: `winery.danskictmanagement.com`.
3. Set the **Document Root** to `/home/<cpanel-user>/winery-pos/public` (outside `public_html` for maximum security).

> **If your cPanel plan does NOT allow changing the subdomain document root** (e.g. it forces `/home/<user>/public_html/winery`):
> 1. Extract the Laravel application into `/home/<cpanel-user>/winery-pos-private/` (outside `public_html`).
> 2. Copy only the contents of `/home/<cpanel-user>/winery-pos-private/public/` into `/home/<cpanel-user>/public_html/winery/`.
> 3. Edit `/home/<cpanel-user>/public_html/winery/index.php` so the `require` paths point to `../../winery-pos-private/vendor/autoload.php` and `../../winery-pos-private/bootstrap/app.php`.
> 4. Never place `.env`, `storage/`, `config/`, or `database/` inside `public_html`.

## 2. Enable SSL (HTTPS)
1. In cPanel, open **SSL/TLS Status** (AutoSSL / Let's Encrypt).
2. Run **AutoSSL** for `winery.danskictmanagement.com` and verify that `https://winery.danskictmanagement.com` loads with a valid SSL certificate.
3. Production Windows and Android apps **require HTTPS**.

## 3. Select PHP Version
1. Open **Select PHP Version** or **MultiPHP Manager** in cPanel.
2. Set `winery.danskictmanagement.com` to **PHP 8.3** or **PHP 8.4** (minimum PHP 8.2).

## 4. Enable Required PHP Extensions
Verify these extensions are enabled in PHP Selector:
- `pdo` & `pdo_mysql`
- `bcmath`
- `openssl`
- `mbstring`
- `fileinfo`
- `ctype`
- `curl`
- `xml` & `dom`
- `tokenizer`
- `gd` (or `imagick` — GD is used for image resizing/thumbnails)
- `zip`

## 5. Upload and Extract the Production ZIP
1. Open **File Manager** in cPanel.
2. Create `/home/<cpanel-user>/winery-pos/`.
3. Upload `Winery-POS-cPanel-Production.zip` and click **Extract**.
4. Confirm `.env.example`, `app/`, `bootstrap/`, `config/`, `database/`, `public/`, `routes/`, `storage/`, and `vendor/` exist inside `/home/<cpanel-user>/winery-pos/`.

## 6. Configure Document Root & `.htaccess`
- Confirm `public/.htaccess` is present (included in the ZIP). It forwards `Authorization` headers (required for Sanctum API tokens) and routes requests to `public/index.php`.
- Confirm `storage/app/public/products/.htaccess` is created automatically on first image upload to block script execution inside uploaded image folders.

## 7. Create the MySQL Database
1. Open **MySQL Databases** in cPanel.
2. Create a new database, e.g. `<cpanel_prefix>_winery_pos`.

## 8. Create and Assign the MySQL Database User
1. Under **MySQL Users**, create a dedicated user with a strong generated password.
2. Under **Add User to Database**, assign that user to `<cpanel_prefix>_winery_pos` with **ALL PRIVILEGES**.

## 9. Configure `.env`
1. Copy `.env.example` to `.env` inside `/home/<cpanel-user>/winery-pos/`.
2. Set:
   ```env
   APP_NAME="Winery POS"
   APP_ENV=production
   APP_DEBUG=false
   APP_URL=https://winery.danskictmanagement.com
   APP_TIMEZONE=Africa/Kampala
   APP_CURRENCY=UGX

   DB_CONNECTION=mysql
   DB_HOST=localhost
   DB_PORT=3306
   DB_DATABASE=<cpanel_prefix>_winery_pos
   DB_USERNAME=<cpanel_prefix>_winery_user
   DB_PASSWORD=<strong-password>

   FILESYSTEM_DISK=public
   SESSION_DRIVER=database
   SESSION_SECURE_COOKIE=true
   CACHE_STORE=database
   QUEUE_CONNECTION=database

   EFRIS_MODE=disabled
   ```

## 10. Generate `APP_KEY`
**With cPanel Terminal (SSH):**
```bash
cd ~/winery-pos
php artisan key:generate --force
```
> **Preserve `APP_KEY`!** Back up your `.env` file securely. If you migrate domains later, keep the same `APP_KEY` so encrypted tokens/settings remain valid.

## 11. Run Database Migrations (Choose ONE Method)
**Method A — Recommended (With cPanel Terminal):**
```bash
cd ~/winery-pos
php artisan migrate --force
```
**Method B — Without Terminal (phpMyAdmin SQL Import):**
1. Open **phpMyAdmin**, select `<cpanel_prefix>_winery_pos`, and click **Import**.
2. Upload `Winery-POS-Database.sql`.
3. Do **not** run both Method A and Method B on the same fresh database; `Winery-POS-Database.sql` already includes the `migrations` history table so future updates can use `php artisan migrate`.

## 12. Create Initial Admin and Cashier Accounts
**With cPanel Terminal:**
```bash
cd ~/winery-pos
php artisan winery:setup
```
Follow the prompts to enter your Business Name, URA TIN (optional), Main Branch, **Admin** email/password, and **Cashier** email/password. No demo users or sample financial records are seeded.

> **If Terminal is unavailable:** Use `php -r` or a one-time local Artisan command before uploading, or run `winery:setup` via a temporary cPanel Cron Job (then delete the cron job immediately). Never leave an open web-based installer script on the server.

## 13. Configure Product Image Storage
**With Terminal:**
```bash
cd ~/winery-pos
php artisan storage:link
```
Even if your host disables `symlink()`, Winery POS also serves product images securely through `/api/v1/images/products/{filename}` with `X-Content-Type-Options: nosniff`, so images work on every cPanel host.

## 14. Set File Permissions
Ensure `storage/` and `bootstrap/cache/` are writable by PHP (`755` for directories, `644` for files; `.env` set to `600`).

## 15. Configure Cron Jobs (Optional / Queue & Housekeeping)
In cPanel **Cron Jobs**, add a once-per-minute scheduler if background jobs are enabled:
```bash
* * * * * cd /home/<cpanel-user>/winery-pos && php artisan schedule:run >> /dev/null 2>&1
```

## 16. Test the API Health Endpoint
Open in a browser or curl:
`https://winery.danskictmanagement.com/api/v1/health`

Expected JSON response:
```json
{
  "status": "ok",
  "app_name": "Winery POS",
  "installation_id": "<uuid>",
  "currency": "UGX",
  "timezone": "Africa/Kampala",
  "efris_mode": "disabled"
}
```

## 17. Test Product Image Uploads
1. Sign in to `https://winery.danskictmanagement.com/business/login` as Admin.
2. Open **Products** -> **+ Add Product**, upload a JPEG/PNG/WebP image (max 5 MB), and save.
3. Confirm the thumbnail displays in the Products table and POS screen.

## 18. Connect the Windows Desktop Application
1. Install `Winery-POS-Windows-Setup.exe` on the shop PC.
2. Launch **Winery POS** — it connects automatically to `https://winery.danskictmanagement.com` (no API URL entry required).
3. Sign in with your Admin or Cashier account.

## 19. Connect the Android Application
1. Install `Winery-POS-Android.apk` on the owner's Android phone.
2. Open **Winery POS** and sign in with your Admin account — it connects automatically to `https://winery.danskictmanagement.com`.

## 20. Create Backups
- **Server Database:** Use cPanel **Backup** or phpMyAdmin **Export** regularly.
- **Windows Offline Terminal:** Admin -> **Settings -> Backup & Restore -> Export Local SQLite Backup**.
