# cPanel & Shared Hosting Production Deployment Guide
## Complete Setup for cPanel Environments with or without Terminal/SSH Access

This guide explains how to deploy **PeopleFlow HRIS** on cPanel shared hosting or managed cloud servers without exposing private Laravel application files to the public internet.

---

## 1. Directory Structure Strategy for cPanel

Never put the entire Laravel project directly inside `public_html`. That exposes your `.env` database passwords and core code to public downloads.

Instead, use the standard safe separation:
- Place the core Laravel files in a private directory **outside** `public_html`:  
  `/home/username/peopleflow_hris/`
- Place the contents of Laravel's `public/` directory inside `public_html` (or subfolder/addon domain).

---

## 2. Preparing Files for Upload

On your local development machine:
1. Run `composer install --no-dev --optimize-autoloader`.
2. Compress the entire `laravel/` project into a ZIP file (excluding `node_modules` or `.git`).
3. Log in to your cPanel File Manager.
4. Upload the ZIP file into your user root directory `/home/username/`.
5. Extract the ZIP into a folder named `peopleflow_hris`.

---

## 3. Configuring the Public Directory

### Option A: If your host allows changing Document Root (Addon Domains)
In cPanel **Domains**, simply set the document root for your domain to:
```
/home/username/peopleflow_hris/public
```
This is the cleanest approach.

### Option B: For Primary Domain (`public_html`)
1. Move all files and folders from `/home/username/peopleflow_hris/public/` directly into `/home/username/public_html/`.
2. Open `/home/username/public_html/index.php` in the cPanel Code Editor.
3. Update the paths to point to your private `peopleflow_hris` directory:

```php
// Change lines around line 19 and line 34:
require __DIR__.'/../peopleflow_hris/vendor/autoload.php';

$app = require_once __DIR__.'/../peopleflow_hris/bootstrap/app.php';
```

4. Create a `.htaccess` file in `/home/username/public_html/` if not present:
```apache
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
```

---

## 4. PHP Version & Extensions in cPanel

1. In cPanel, find **MultiPHP Manager** or **Select PHP Version**.
2. Select **PHP 8.2** or **PHP 8.3**.
3. Under **PHP Extensions**, ensure the following are enabled:
   - `pdo_mysql`
   - `mbstring`
   - `openssl`
   - `bcmath`
   - `curl`
   - `xml`
   - `zip`
   - `fileinfo`
   - `intl`

---

## 5. MySQL Database Creation via cPanel

1. Go to **MySQL Database Wizard** in cPanel.
2. Step 1: Create Database: `username_peopleflow`
3. Step 2: Create User: `username_hrisuser` with a strong password.
4. Step 3: Grant **ALL PRIVILEGES** to the user for this database.

---

## 6. Configuring `.env` File

In cPanel File Manager, open `/home/username/peopleflow_hris/.env` (enable "Show Hidden Files" in File Manager settings):

```ini
APP_NAME="PeopleFlow HRIS"
APP_ENV=production
APP_KEY=base64:YOUR_GENERATED_KEY_HERE
APP_DEBUG=false
APP_URL=https://yourdomain.com

APP_TIMEZONE="Asia/Dhaka"
APP_CURRENCY="BDT"

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=username_peopleflow
DB_USERNAME=username_hrisuser
DB_PASSWORD=YourStrongDatabasePassword123#
```

---

## 7. Running Migrations on cPanel

### If Terminal is available in cPanel:
Open the **Terminal** icon in cPanel:
```bash
cd /home/username/peopleflow_hris
php artisan migrate --force --seed
```

### If Terminal / SSH is NOT available in cPanel:
You can temporarily add a secure route in `routes/web.php` or create a temporary script `/home/username/public_html/install-db.php`:
```php
<?php
// Secure with secret token
if ($_GET['token'] !== 'MySuperSecretToken2026') {
    die('Forbidden');
}

require __DIR__.'/../peopleflow_hris/vendor/autoload.php';
$app = require_once __DIR__.'/../peopleflow_hris/bootstrap/app.php';

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->call('migrate', ['--force' => true, '--seed' => true]);

echo "Migration output: " . $kernel->output();
// DELETE THIS FILE IMMEDIATELY AFTER RUNNING!
```
Execute once in browser: `https://yourdomain.com/install-db.php?token=MySuperSecretToken2026`, then **immediately delete** `install-db.php`.

---

## 8. Setting up Cron Jobs in cPanel

1. Navigate to **Cron Jobs** in cPanel.
2. Under "Add New Cron Job", select **Once Per Minute** (`* * * * *`).
3. In the Command field, enter:
```bash
/usr/local/bin/php /home/username/peopleflow_hris/artisan schedule:run >> /dev/null 2>&1
```
*(Check your cPanel documentation or running `which php` in Terminal to verify the exact path to PHP)*.

---

## 9. Verification & Post-Install Checklist

1. Visit your domain: `https://yourdomain.com/login`.
2. Confirm HTTPS certificate is active (via cPanel **AutoSSL**).
3. Log in with seeded HR Admin credentials:
   - Email: `farhana.chowdhury@peopleflow.com`
   - Password: `password123`
4. Confirm Dashboard KPI cards, Chart.js trends, Employee Directory, and Payslips load with live MySQL data.
