# LIS Portal — cPanel Deployment Guide

## Requirements
| Requirement | Minimum |
|---|---|
| PHP | 8.2+ (set in cPanel → MultiPHP Manager) |
| MySQL | 5.7+ or MariaDB 10.3+ |
| mod_rewrite | Enabled (ask host if unsure) |
| SSH/Terminal | Recommended (cPanel → Terminal) |
| Composer | v2 (install via SSH or upload vendor/) |

---

## Option A — Subdomain (Recommended)
**Result:** `http://lis.yourdomain.com`

### Step 1 — Create the subdomain
- cPanel → **Domains** → **Subdomains**
- Subdomain: `lis`   Domain: `yourdomain.com`
- Document Root: `/home/USERNAME/lis-portal/public`   ← point to Laravel's public/ folder

### Step 2 — Upload files
Upload the full `lis-portal/` folder to `/home/USERNAME/lis-portal/`  
(use cPanel File Manager or FTP — exclude `.git/`, `node_modules/`)

### Step 3 — Create MySQL database
- cPanel → **MySQL Databases**
- Create database: `USERNAME_lisportal`
- Create user: `USERNAME_lisuser` with strong password
- Add user to database — grant **All Privileges**

### Step 4 — Configure .env
Edit `/home/USERNAME/lis-portal/.env`:
```env
APP_NAME="LIS Portal"
APP_ENV=production
APP_KEY=                          # will be generated in Step 6
APP_DEBUG=false
APP_URL=http://lis.yourdomain.com

LOG_CHANNEL=daily

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=USERNAME_lisportal
DB_USERNAME=USERNAME_lisuser
DB_PASSWORD=your_strong_password

SESSION_DRIVER=file
CACHE_STORE=file
QUEUE_CONNECTION=sync
```

### Step 5 — Set permissions (SSH)
```bash
cd /home/USERNAME/lis-portal
chmod -R 755 storage bootstrap/cache
chmod -R 644 storage/logs
```

### Step 6 — Run artisan commands (SSH or cPanel Terminal)
```bash
cd /home/USERNAME/lis-portal
composer install --no-dev --optimize-autoloader
php artisan key:generate
php artisan migrate --force
php artisan db:seed --force          # seeds LIS KM8.1 NB + KM6.1 NB devices
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan storage:link
```

---

## Option B — Subdirectory (no subdomain)
**Result:** `http://yourdomain.com/lis-portal`

### Step 1 — Upload files
Upload entire `lis-portal/` folder into `public_html/lis-portal/`

### Step 2 — Add root redirect .htaccess
Create `/home/USERNAME/public_html/lis-portal/.htaccess`:
```apache
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
```
*(This file is included in the package as `htaccess_subdirectory.txt` — rename it)*

### Step 3 — Update .env
```env
APP_URL=http://yourdomain.com
```

### Step 4 — Update routes
The portal routes already use the `/lis-portal` prefix — no change needed.  
All URLs will be `http://yourdomain.com/lis-portal/dashboard` etc.

### Step 5 — Repeat Steps 3–6 from Option A

---

## Composer Without SSH
If your host has no SSH, upload the `vendor/` folder directly after running locally:
```bash
# On your local machine:
cd lis-portal
composer install --no-dev --optimize-autoloader
# Then zip & upload the full folder including vendor/
```

---

## Cron Job for Automatic Schedule
Add in cPanel → **Cron Jobs** — run every minute:
```
* * * * * /usr/local/bin/php /home/USERNAME/lis-portal/artisan schedule:run >> /dev/null 2>&1
```

---

## Troubleshooting
| Problem | Fix |
|---|---|
| 500 error | Check `storage/logs/laravel.log`; ensure `storage/` is writable |
| Page not found | Verify mod_rewrite is on; check `public/.htaccess` exists |
| DB connect error | Verify MySQL credentials in `.env`; run `php artisan config:clear` |
| White screen | Set `APP_DEBUG=true` temporarily to see error |
| Sessions broken | Set `SESSION_DRIVER=file`, check `storage/framework/sessions/` is writable |
