# Deployment guide (WHM/cPanel, AlmaLinux)

This is the short version for Phase 1. The full guide grows with each phase.

## 1. Server requirements

- PHP 8.3 or newer, set in MultiPHP Manager, with these extensions: `mbstring`, `intl`, `pdo_mysql`, `gd`, `exif`, `fileinfo`, `bcmath`, `zip`, `openssl` (and `redis` if available).
- MySQL 8 or newer, or MariaDB 10.6 or newer. Create the database with `utf8mb4` / `utf8mb4_unicode_ci`.
- SSH access and Composer 2.

## 2. Upload and install

```bash
cd ~
git clone <your-repo> app        # or upload the folder to /home/USER/app
cd app
composer install --no-dev --optimize-autoloader
cp .env.example .env && php artisan key:generate
```

Then edit `.env` with production values:

- `APP_ENV=production`, `APP_DEBUG=false`, `APP_URL=https://yourdomain.pk`
- `SESSION_SECURE_COOKIE=true`
- the `DB_*` values

```bash
chmod 600 .env
php artisan migrate --force
php artisan db:seed --force          # set SUPER_ADMIN_* first, remove them afterwards
php artisan storage:link
```

Build the assets on your own computer (`npm ci && npm run build`) and upload `public/build/`. Node is not needed on the server.

**Back up `APP_KEY` somewhere safe and offline.** Without it, encrypted CNICs and addresses cannot be read.

## 3. Document root

Point the domain's document root to `/home/USER/app/public`. **Never put the whole app inside `public_html`.**

If you can't change the document root, replace `public_html` with a symlink:

```bash
mv ~/public_html ~/public_html.bak && ln -s ~/app/public ~/public_html
```

## 4. Cron (cPanel → Cron Jobs)

```
* * * * * cd /home/USER/app && php artisan schedule:run >> /dev/null 2>&1
```

## 5. Queue worker

- **With root or Supervisor access:** run `php artisan queue:work --tries=3 --max-time=3600` under Supervisor.
- **Without Supervisor:** add a second cron entry:
  ```
  * * * * * cd /home/USER/app && php artisan queue:work --stop-when-empty --max-time=55 >> /dev/null 2>&1
  ```

## 6. On every deploy

```bash
php artisan down
git pull && composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan config:cache && php artisan route:cache && php artisan view:cache && php artisan event:cache
php artisan up
```

## 7. Cloudflare

- SSL mode: Full (strict).
- Bypass the cache for `/*/admin*`, `/*/dashboard*`, `/*/login*` and `/*/confirm-password*`.
- `TRUSTED_PROXIES=*` is already set, so real visitor IPs are used for rate limiting.

## 8. Check that private files are protected

Each of these must return 403 or 404:

```
https://yourdomain.pk/.env
https://yourdomain.pk/storage/app/private/
https://yourdomain.pk/composer.json
https://yourdomain.pk/vendor/
```
