# Deploying rfoof to GoDaddy cPanel (rfoof.online)

## Environment

- Python 3.9 (system `/bin/python3`)
- MySQL (cPanel)
- Packages installed via `pip3 install --user`
- Django 4.2 LTS

## 1. Create MySQL Database (cPanel)

cPanel → **MySQL Databases**:

1. Create database: `rfoof_db` → cPanel saves it as `rfoof_rfoof_db`
2. Create user: `rfoof_user` → saved as `rfoof_rfoof_user`. Strong password.
3. Add user to database → grant **ALL PRIVILEGES**.

Note the final prefixed names.

## 2. Upload the code

**Option A — Git (recommended):**

SSH into the server:
```bash
cd ~
git clone https://github.com/YOUR_USER/rfoof.git rfoof
```

**Option B — File Manager:**

Upload a zip of the project to `/home/rfoof/` and extract it so the
structure is `/home/rfoof/rfoof/manage.py`.

## 3. Configure environment

```bash
cd ~/rfoof
cp .env.cpanel .env
nano .env
```

Fill in:
```
SECRET_KEY=<generate with: python3 -c "import secrets; print(secrets.token_urlsafe(64))">
DEBUG=False
ALLOWED_HOSTS=rfoof.online,www.rfoof.online

DB_NAME=rfoof_rfoof_db
DB_USER=rfoof_rfoof_user
DB_PASSWORD=<your password>
DB_HOST=localhost
DB_PORT=3306

CORS_ALLOWED_ORIGINS=https://rfoof.online,https://www.rfoof.online
```

Upload `firebase-adminsdk.json`:
```bash
chmod 600 firebase-adminsdk.json .env
```

## 4. Install + migrate

```bash
cd ~/rfoof
bash deploy_cpanel.sh
```

## 5. Point the domain to the app

The app needs to live in the **document root** for `rfoof.online`.

In cPanel → **Domains** (or **Addon Domains** / **Subdomains**), check what
the document root is for `rfoof.online`. It's usually:
```
/home/rfoof/public_html
```

You have two choices:

**Option A — Symlink (cleanest):**
```bash
rm -rf ~/public_html    # remove default placeholder (back up if needed)
ln -s ~/rfoof ~/public_html
```

**Option B — Change document root:**

In cPanel → **Domains** → edit `rfoof.online` → set document root to `/home/rfoof/rfoof`.

## 6. Verify .htaccess is active

The `.htaccess` in the project root tells Apache to route requests to
`passenger_wsgi.py`. If Passenger isn't available on GoDaddy (likely), the
RewriteRule fallback handles it.

If you get a 500 error, check `~/logs/error.log` or cPanel → **Errors**.

## 7. Create superuser

```bash
cd ~/rfoof
python3 manage.py createsuperuser
```

## 8. Test

- `https://rfoof.online/api/v1/health/` → `{"status": "ok"}`
- `https://rfoof.online/admin/` → Django admin login

## Troubleshooting

- **500 Internal Server Error**: check `~/logs/error.log`. Usually a missing
  package or wrong path in `.htaccess`.
- **Module not found**: run `pip3 install --user -r requirements.txt` again.
- **Static files 404**: run `python3 manage.py collectstatic --noinput`.
- **Changes not visible**: `touch ~/rfoof/tmp/restart.txt`.
- **Passenger not recognized**: GoDaddy may not have mod_passenger. In that
  case we'll switch to a FCGI/CGI dispatch script — let me know.

## Future deploys

```bash
cd ~/rfoof
git pull origin main
bash deploy_cpanel.sh
```
