# cPanel Deployment Guide

## 1. Prerequisites

- cPanel hosting with **PHP 8.1+** support (most providers offer this)
- MySQL/MariaDB 10.3+ (any modern shared host)
- A subdomain you can point at this backend (recommended: `api.yourdomain.com`)

## 2. Create the database

1. cPanel → **MySQL Databases**
2. Create database: `lifeos` (cPanel will prefix it → `cpaneluser_lifeos`)
3. Create user: `lifeosapi` with a strong password
4. Add user to database with **ALL PRIVILEGES**
5. Note down: DB name, DB user, DB password — you'll need them in step 5.

## 3. Import the schema

1. cPanel → **phpMyAdmin** → select `cpaneluser_lifeos`
2. **Import** tab → choose `sql/01_schema.sql` → Go
3. Repeat with `sql/02_seed.sql`, then `sql/03_schema_tasks_goals.sql`
4. Verify under "Structure" — you should see ~17 tables.

> If your file is too large, use the chunked-upload trick: increase `upload_max_filesize` in cPanel's MultiPHP INI Editor, or split the SQL.

## 4. Upload the backend

**Option A — File Manager:**
1. cPanel → Subdomains → create `api.yourdomain.com` pointing to `/public_html/api`.
2. cPanel → File Manager → navigate to `/public_html/api`.
3. Upload the entire `backend/` folder, then **move all its contents up one level** so `index.php` is directly under `/public_html/api`.

**Option B — FTP:** Same idea, just use FileZilla.

After upload, the structure should be:
```
public_html/api/
├── .htaccess
├── index.php
├── config/
├── lib/
├── api/
├── cron/
└── uploads/
```

## 5. Configure

1. In File Manager, copy `config/config.sample.php` → `config/config.php`.
2. Edit `config/config.php`:
   ```php
   'db' => [
     'host' => 'localhost',
     'name' => 'cpaneluser_lifeos',
     'user' => 'cpaneluser_lifeosapi',
     'pass' => 'YOUR_DB_PASSWORD',
   ],
   'jwt' => [
     'secret' => 'PASTE_64_CHAR_HEX_HERE',  // generate via terminal or online
   ],
   ```
3. Set folder permissions:
   - `config/` → `0755`, `config/config.php` → `0640`
   - `uploads/avatars/` → `0755`

## 6. Set PHP version

cPanel → **MultiPHP Manager** → select `api.yourdomain.com` → set to **PHP 8.1** (or 8.2/8.3).

## 7. Test it

Visit:
- `https://api.yourdomain.com/health` → `{"ok":true,"data":{"status":"healthy"}}`
- `POST https://api.yourdomain.com/auth/signup` with JSON `{"email":"you@x.com","password":"test1234"}` → returns a JWT.

If you get 500: check cPanel → **Errors** for the PHP error log.
If you get 404 on every route: `.htaccess` rewriting is disabled — contact your host to enable `mod_rewrite`.

## 8. Schedule the deletion cron

cPanel → **Cron Jobs** → add:
- Schedule: `0 3 * * *` (daily at 3 AM)
- Command: `/usr/local/bin/php /home/CPANELUSER/public_html/api/cron/process_deletions.php >> /home/CPANELUSER/logs/lifeos-cron.log 2>&1`

## 9. Lock down CORS (production)

Edit `.htaccess`, replace:
```
Header always set Access-Control-Allow-Origin "*"
```
with your actual frontend domain:
```
Header always set Access-Control-Allow-Origin "https://app.yourdomain.com"
```

## 10. (Optional) Force HTTPS

Add to `.htaccess` (top of file):
```
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
```

## Done ✅

The backend is live. Next: Phase 2 — wire the React frontend (separate chat).
