# Deployment Guide for Shared Hosting

## ⚠️ Important: Laravel Deployment Requirements

**You CANNOT simply unzip everything under `public_html`.** Laravel requires a specific structure for security and functionality.

## Option 1: Standard Laravel Structure (Recommended)

### Step 1: Build Frontend Assets
Before uploading, build your frontend assets:
```bash
cd hr-admin
npm install
npm run build
```

### Step 2: Upload Structure
On your shared hosting, you have two options:

#### Option A: If you have access to the directory above public_html
```
/home/username/
├── hr-admin/          (upload entire hr-admin folder here)
│   ├── app/
│   ├── bootstrap/
│   ├── config/
│   ├── database/
│   ├── public/        (this will be symlinked to public_html)
│   ├── resources/
│   ├── routes/
│   ├── storage/
│   ├── vendor/
│   └── ...
└── public_html/       (symlink to hr-admin/public)
```

Then create a symlink:
```bash
ln -s /home/username/hr-admin/public /home/username/public_html
```

#### Option B: If you can only use public_html (Most Common)
Upload the entire `hr-admin` folder structure, but configure your web server:

```
public_html/
├── .htaccess          (see below)
├── index.php          (copy from hr-admin/public/index.php)
├── app/               (from hr-admin/app/)
├── bootstrap/         (from hr-admin/bootstrap/)
├── config/            (from hr-admin/config/)
├── database/          (from hr-admin/database/)
├── resources/         (from hr-admin/resources/)
├── routes/            (from hr-admin/routes/)
├── storage/           (from hr-admin/storage/)
├── vendor/            (from hr-admin/vendor/)
└── ... (all other files)
```

### Step 3: Create/Update .htaccess in public_html
Create a `.htaccess` file in `public_html`:

```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>
```

### Step 4: Update index.php
Update the paths in `public_html/index.php`:

```php
<?php

use Illuminate\Foundation\Application;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/storage/framework/maintenance.php')) {
    require $maintenance;
}

// Register the Composer autoloader...
require __DIR__.'/vendor/autoload.php';

// Bootstrap Laravel and handle the request...
/** @var Application $app */
$app = require_once __DIR__.'/bootstrap/app.php';

$app->handleRequest(Request::capture());
```

### Step 5: Configure Environment
1. Create `.env` file in `public_html` (or copy from `.env.example` if it exists)
2. Set your database credentials, app URL, etc.
3. Generate application key:
   ```bash
   php artisan key:generate
   ```

### Step 6: Set Permissions
Set proper permissions (usually via cPanel File Manager or SSH):
```bash
chmod -R 755 storage
chmod -R 755 bootstrap/cache
```

### Step 7: Run Migrations
```bash
php artisan migrate
```

## Option 2: Subdirectory Deployment

If you need to deploy in a subdirectory (e.g., `public_html/hr-admin/`):

1. Upload entire `hr-admin` folder to `public_html/hr-admin/`
2. Move contents of `hr-admin/public/` to `public_html/hr-admin/`
3. Update `index.php` paths to point to parent directories
4. Configure `.env` with correct `APP_URL`

## Pre-Deployment Checklist

- [ ] Run `npm run build` to compile frontend assets
- [ ] Remove `node_modules` folder (not needed on server)
- [ ] Remove `.git` folder if present
- [ ] Ensure `vendor/` folder is uploaded (or run `composer install --no-dev` on server)
- [ ] Create `.env` file with production settings
- [ ] Set `APP_ENV=production` and `APP_DEBUG=false` in `.env`
- [ ] Configure database credentials
- [ ] Set proper file permissions
- [ ] Run migrations
- [ ] Clear cache: `php artisan config:clear && php artisan cache:clear`

## Common Issues

1. **500 Error**: Check file permissions and `.env` configuration
2. **Asset Loading Issues**: Ensure `npm run build` was run and `public/build/` exists
3. **Database Errors**: Verify database credentials in `.env`
4. **Permission Denied**: Set `storage/` and `bootstrap/cache/` to 755

## Need Help?

If your shared hosting doesn't support the standard Laravel structure, contact your hosting provider about:
- PHP version (Laravel 11 requires PHP 8.2+)
- Composer support
- SSH access for running artisan commands
- Ability to set document root or create symlinks

