# Namecheap cPanel hosting setup

Use the **PHP** runner (`run.php`). Shared cPanel hosts PHP + cron reliably; Python is optional and often harder.

## 1. Upload outside `public_html`

Via File Manager or FTP, put the project here (example):

```text
/home/YOURUSER/email-whatsapp-digest/
  run.php
  .env
  php/
  logs/
```

Do **not** put `.env` inside `public_html` (keeps secrets off the web).

## 2. Enable PHP IMAP

cPanel → **Select PHP Version** (or MultiPHP Manager) → **Extensions** → enable:

- `imap`
- `curl`
- `mbstring` (usually on)

Use PHP **8.1+** if available.

## 3. Create `.env`

Copy `.env.example` → `.env` and fill:

- `EMAIL_ACCOUNTS` (JSON, one line)
- UltraMsg or Meta WhatsApp keys
- `WHATSAPP_TO` (your number, e.g. `+9665...`)
- Optional `OPENAI_API_KEY`

## 4. Create log folder

```text
/home/YOURUSER/email-whatsapp-digest/logs/
```

Permissions: `755` is fine.

## 5. Test in Terminal (SSH) or Cron once

Find PHP path (Namecheap often):

```bash
which php
# or
ls /usr/local/bin/php
```

Dry run:

```bash
cd ~/email-whatsapp-digest
/usr/local/bin/php run.php --dry-run
```

Live send:

```bash
/usr/local/bin/php run.php
```

If SSH is unavailable: cPanel → **Cron Jobs** → add a one-time test command (below), wait one minute, check `logs/cron.log`.

## 6. Daily cron (cPanel → Cron Jobs)

Set timezone in cPanel if offered, or convert your local time to server time.

Example: every day at **20:00**:

```cron
0 20 * * * /usr/local/bin/php /home/YOURUSER/email-whatsapp-digest/run.php >> /home/YOURUSER/email-whatsapp-digest/logs/cron.log 2>&1
```

Replace:

- `YOURUSER` with your cPanel username
- `/usr/local/bin/php` with the path from `which php` if different

## 7. Optional professional GUI dashboard

If you want an admin UI for operations:

1. Keep the agent in a private path, e.g.:
   - `/home/YOURUSER/email-whatsapp-digest-private`
2. Copy `dashboard/index.php` from the project into a public dashboard path, e.g.:
   - `/home/YOURUSER/digital.whitevue.com/dashboard/index.php`
3. Edit dashboard file and set app root path:
   - Find `$root = ...` near top of `index.php`
   - Set fallback to your private path, e.g.:
   - `$root = (string) (getenv('DIGEST_APP_ROOT') ?: '/home/YOURUSER/email-whatsapp-digest-private');`
4. In private `.env`, set:
   - `DASHBOARD_PASSWORD=strong-unique-password`
5. Open:
   - `https://your-domain.com/dashboard/`

Dashboard features:
- secure sign-in
- run dry test
- send live digest immediately
- digest preview
- cron log tail viewer

## Troubleshooting

| Problem | Fix |
|---------|-----|
| `PHP IMAP extension is not enabled` | Enable `imap` in Select PHP Version |
| Gmail login failed | Use a Google **App Password** (2FA on) |
| Outlook login failed | IMAP must be allowed; some M365 tenants need admin/OAuth |
| UltraMsg not sending | Instance must be QR-authenticated in ultramsg.com |
| Meta API error about template | Use UltraMsg for personal digests, or send via an approved template |
| Cron silent | Check `logs/cron.log` and cron email in cPanel |

## Security

- Keep project **outside** `public_html`
- Never commit `.env`
- Prefer UltraMsg for personal “message myself” digests