<!-- Author By : zulfazdliabuas@gmail.com | Date : 2026 -->
# DEPLOY.md

## Environment
- Domain: `cpers-imejparking.com`
- Document root: `public_html` (main domain, cannot change)
- Laravel app location: `public_html` (entire app in web root)
- Public path override required in `index.php`:

```php
$app = require_once __DIR__.'/bootstrap/app.php';
$app->usePublicPath(__DIR__);
$app->handleRequest(Request::capture());
```

## Before Deploy (Local)
1. Pull latest code.
2. Apply code changes.
3. Build frontend assets:

```bash
npm run build
```

4. Verify local `build/` contains:
- `build/manifest.json`
- `build/assets/*` (hashed css/js files)

## Deploy Steps (Server)
0. (Optional) Pull latest code from GitHub:

```bash
cd ~/public_html
git branch --show-current
git pull origin main
```

Notes:
- Server remote should use SSH format: `git@github.com:<user>/<repo>.git`
- If error `Permission denied (publickey)`, authorize server SSH key in GitHub first.
- If `build/` is not committed to git, still upload full `build/` manually after pull.

1. Upload changed Laravel files to `public_html`.
- Example: `app/`, `resources/`, `routes/`, `config/`, etc.

2. Upload and replace entire `build/` folder to:
- `public_html/build`

3. If `composer.json` or `composer.lock` changed, run:

```bash
composer install --no-dev --optimize-autoloader
```

4. Clear Laravel caches:

```bash
php artisan optimize:clear
```

5. Hard refresh browser:
- `Ctrl + F5`

## Permissions
- Folders: `755`
- Files: `644`
- Do not use `777` unless temporary debugging.

## Quick Verification
1. Open:
- `https://cpers-imejparking.com/build/manifest.json`
- `https://cpers-imejparking.com/build/assets/<hash>.css`

2. Login page should render with full styles.

## Common Issues

### 1) `Vite manifest not found at .../public/build/manifest.json`
Cause:
- Laravel still using default `public_path()` (`public_html/public`).

Fix:
- Ensure `index.php` contains:

```php
$app->usePublicPath(__DIR__);
```

- Ensure assets are in `public_html/build`, not `public_html/public/build`.
- Clear cache (`php artisan optimize:clear`).

### 2) CSS/JS 404 on `/build/assets/...`
Cause:
- `manifest.json` and `assets` files mismatch or wrong location.

Fix:
- Re-upload entire `build/` folder (not individual files).

### 3) Page still old after deploy
Fix:
- Hard refresh browser (`Ctrl + F5`).
- Clear `storage/framework/views/*` if needed.

## Recommended Deploy Habit
Always deploy these together:
1. Backend code changes
2. Full `build/` folder
3. Cache clear command

This prevents manifest/hash mismatch issues.

## Quick Git Checks
```bash
cd ~/public_html
git rev-parse --is-inside-work-tree
git remote -v
git status -sb
```
