# Deploying this app

Laravel 10.50 · PHP 8.1 · the host is cPanel/LiteSpeed with `proc_open` disabled.

## What to upload

Upload everything in this directory **except** these, which are local junk:

- `app.zip` · a 28 MB copy of the project, including `vendor/`
- `composer.phar`
- `sql/` and `*.md` are optional (reference only, not served)

`vendor/` **must** be uploaded. `proc_open` is disabled on the host, so
`composer install` cannot be run there.

## Document root

Document root must point at `public/`, never at the project root.

Right now it does not · the API answers on
`https://usajobalert.gremacorp.com/public/api/...`, and that `/public` segment
is the giveaway. With the root one level too high, everything beside `public/`
is served too. Check, from a machine that is **not** on the office network:

```bash
curl -s -o /dev/null -w '%{http_code}\n' https://usajobalert.gremacorp.com/.env
curl -s -o /dev/null -w '%{http_code}\n' https://usajobalert.gremacorp.com/storage/logs/laravel.log
curl -s -o /dev/null -w '%{http_code}\n' https://usajobalert.gremacorp.com/composer.json
```

`403` or `404` for all three is fine. **Any `200` means the database password,
the `APP_KEY` and the Firebase configuration are readable by anyone**, which is
an incident: rotate those credentials, then fix the document root.

The fix is to repoint the domain's document root at
`/home/vuhhrqsn/usajobalert.gremacorp.com/public` in cPanel. The API URL then
loses the `/public` segment, so update the iOS app and the Postman `baseUrl`
variable at the same time.

Until that is done, the stopgap is a `.htaccess` in the project root denying
everything except `public/`. That is a patch over a misconfiguration, not a
substitute for fixing it.

## After uploading

1. **`.env`** · if the server already has one, leave it alone. Otherwise copy
   `.env.example` to `.env` and fill in `DB_*`, `FCM_PROJECT_ID` and
   `FCM_CREDENTIALS_PATH`. Keep `APP_DEBUG=false`.

2. **App key** · only if `APP_KEY` is empty:

   ```bash
   php artisan key:generate
   ```

3. **Permissions** · the web user must be able to write to these, or every
   request 500s:

   ```bash
   chmod -R 775 storage bootstrap/cache
   ```

4. **Database** · either

   ```bash
   php artisan migrate --force
   ```

   or, with no CLI access, run `sql/schema.sql` in phpMyAdmin. They are
   equivalent.

   **If the database already exists** and `job_alerts` still has a `client_id`
   column, that column has been renamed to `alert_id`. `php artisan migrate`
   handles it (migration `2026_08_01_000005`). Without CLI access, run
   `sql/alter_2026_08_01_alert_id.sql` in phpMyAdmin instead · do not run both,
   and do not run either against a database freshly built from `schema.sql`,
   which already has the new shape. Check which you have with:

   ```sql
   SELECT column_name FROM information_schema.columns
   WHERE table_schema = DATABASE() AND table_name = 'job_alerts'
     AND column_name IN ('client_id', 'alert_id');
   ```

5. **Clear anything cached from the broken build:**

   ```bash
   php artisan config:clear
   php artisan route:clear
   php artisan cache:clear
   php artisan view:clear
   ```

   Do not run `config:cache` until the site is confirmed working · a cached
   config from a half-configured `.env` is a confusing failure to debug.

6. **Cron** · one entry, as the site user. It is the scheduler tick, not the
   broadcast; Laravel decides from `App\Console\Kernel` that `push:broadcast`
   is due every fifth minute:

   ```cron
   * * * * * cd /home/vuhhrqsn/usajobalert.gremacorp.com && php artisan schedule:run >> /dev/null 2>&1
   ```

   Do not add a second line calling `push:broadcast` directly · you would get
   overlapping broadcasts and double notifications.

7. **Firebase credentials** · see the next section.

## Push notifications

The service account JSON is at
`storage/firebase/usa-jobs-joychin-firebase-adminsdk-fbsvc-8e6c213768.json`.
Upload `storage/firebase/` along with everything else · including the
`.htaccess` beside it, which is what stops it being served.

No `.env` entry is required. `FcmService` looks in this order:

1. `FCM_CREDENTIALS_PATH`, absolute or relative to the project root
2. failing that, whatever `*.json` is in `storage/firebase/`

The project id is read from inside the file, so `FCM_PROJECT_ID` is optional
too.

Verify it before trusting it:

```bash
php artisan fcm:check                       # credentials + real token exchange
php artisan fcm:check --send=<device_id>    # one real notification
php artisan push:broadcast --dry-run        # lists targets, sends nothing
```

`fcm:check` reports "Google accepted the credentials and rejected the dummy
device token" on success · that is the correct outcome, it proves the key
signs and the account is enabled without notifying anyone.

Tighten the permissions once uploaded:

```bash
chmod 640 storage/firebase/*.json
```

### This key is exposed while the document root is wrong

The file holds an RSA private key. `storage/` is only unreachable over HTTP
while the document root points at `public/` · and right now it does not (see
above). Check it, from off the office network:

```bash
curl -s -o /dev/null -w '%{http_code}\n' \
  https://usajobalert.gremacorp.com/storage/firebase/usa-jobs-joychin-firebase-adminsdk-fbsvc-8e6c213768.json
```

A `200` means anyone can send push notifications to every user of the app as
you. That is an incident: revoke the key in the Firebase console (Project
settings · Service accounts), generate a new one, and raise it in the Claude
Hotline chat.

The durable fix is either of:

- point the document root at `public/`, or
- move the JSON outside the project, e.g.
  `/home/vuhhrqsn/secrets/firebase-service-account.json`, and set
  `FCM_CREDENTIALS_PATH` to it. This works today and does not depend on the
  document root being fixed first.

## Checking it works

```bash
php artisan route:list                 # should list the 8 /api routes
curl -i https://usajobalert.gremacorp.com/api/alerts
                                       # expect 401 "Device token missing"
php artisan push:broadcast --dry-run   # lists targets, sends nothing
```

A 401 from `/api/alerts` is the healthy answer · it proves routing, the
middleware stack and device auth are all live.

## Housekeeping on the server

Delete `public/error_log` if it is there. It is world-readable over HTTP and
leaks absolute filesystem paths.
