# Installation Guide — BCT Website (v1.5.3)

This package contains everything: the website code, all texts (EN/FR), the logo, board photos (current and past),
the slideshow, all photo albums (including "Bamendjou's King Visit") and the event flyers.

Choose the section that matches your new server:

| Your new server | Use |
|---|---|
| **cPanel account** (Apache already runs the websites; you manage the app yourself with Python) | **Part A** |
| **Plain Linux server with root** (no cPanel) — AlmaLinux/Rocky/RHEL 8–9 or Ubuntu/Debian | **Part B** |
| You want to **move the live site with all admin changes** (edits, messages, uploads) | Part A or B, then **Part C** |

Requirements: Python 3.9 or newer (3.11 recommended), about 600 MB of disk, the domain's DNS under your control.

---

## Part A — cPanel account, managed with Python commands

### A1. Upload and unzip
```bash
scp BCT-Website-Complete.zip CPANELUSER@SERVER_IP:~/          # from your computer
ssh CPANELUSER@SERVER_IP
unzip BCT-Website-Complete.zip                                # creates ~/bct-website
cd ~/bct-website
```
(If you received the package in parts: upload all `.part-*` files, then
`cat BCT-Website-Complete.zip.part-* > BCT-Website-Complete.zip` before unzipping.)

### A2. Python environment
```bash
python3.11 --version || python3 --version      # need 3.9+; ask your host for Python 3.11 if older
python3.11 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
```

### A3. Settings
```bash
cp settings.ini.example settings.ini
nano settings.ini
```
Set at least:
```ini
[server]
host = 127.0.0.1
port = 8035            ; any free port; must match .htaccess below
debug = false
[site]
base_url = https://bandjouncommunitytexas.org
secure_cookies = true  ; false only while testing over plain http://
[smtp]
password =             ; Gmail App Password (or set it later in Admin › Settings & Email)
```

### A4. Load all content (one time, 1–3 minutes)
```bash
flask --app app import-content content
```
Ends with `Import complete.` and lists 5 albums, 9 current board members and the 8-member Past Executive Board.
Creates admin users **webadmin1** / **webadmin2** (see "Admin accounts" below).

### A5. Start the app
```bash
bash start.sh          # prints "OK: running ... answers 200"
```
(The scripts use `venv/bin/python` directly, so you don't need `source venv/bin/activate` for them.)

### A6. Connect the domain (Apache → app)
```bash
cp deploy/cpanel-htaccess.txt ~/public_html/.htaccess     # back up any existing .htaccess first
nano ~/public_html/.htaccess                              # port must match settings.ini
```
- HTTPS: cPanel › SSL/TLS Status › **Run AutoSSL** (after DNS points to the server).
- If the site shows **500/503**: Apache's proxy module is off. In WHM › EasyApache 4 › Apache Modules, enable
  `mod_proxy` and `mod_proxy_http` (or ask the host).

### A7. Keep it running (cPanel › Cron Jobs)
```
@reboot /bin/bash /home/CPANELUSER/bct-website/start.sh >/dev/null 2>&1
*/5 * * * * /bin/bash /home/CPANELUSER/bct-website/start.sh >/dev/null 2>&1
```

### A8. Everyday commands (from the site folder, e.g. `cd ~/bct-website`)
| Task | Command |
|---|---|
| Start | `bash start.sh` |
| Stop | `bash stop.sh` |
| Restart | `bash restart.sh` |
| Is it running? | `bash status.sh` |
| Logs | `tail -f logs/app.log` |
| Apply a code update zip | `unzip -o update.zip -d <folder that contains bct-website>`, then `bash restart.sh` |
| CLI commands (`flask …`) | `source venv/bin/activate` first |

---

## Part B — Plain Linux server with root (automatic installer)

```bash
scp BCT-Website-Complete.zip root@SERVER_IP:~/
ssh root@SERVER_IP
dnf install -y unzip        # Ubuntu/Debian: apt install -y unzip
unzip BCT-Website-Complete.zip && cd bct-website
bash deploy/install.sh                # adds nginx in front
# bash deploy/install.sh --no-nginx   # cPanel/WHM server where you have root (then use deploy/cpanel-apache-proxy.conf)
```
The installer: installs Python 3.11 (and ffmpeg if available), copies the site to `/opt/bct`, creates user `bct`
and the venv, imports all content, starts the `bct` systemd service on 127.0.0.1:8085, configures SELinux and
firewalld, and installs the nginx config.

Then point DNS to the server and enable HTTPS:
```bash
dnf install -y epel-release && dnf install -y certbot python3-certbot-nginx
certbot --nginx -d bandjouncommunitytexas.org -d www.bandjouncommunitytexas.org
```
Service commands: `systemctl status|restart bct`, logs: `journalctl -u bct -f`.
Code updates: unzip the new package, `cd bct-website`, `sudo bash deploy/update.sh`.

---

## Part C — Moving the live site with all admin changes

The package contains the **original** content. Anything changed later through the admin (text edits, new
events, uploaded photos, contact messages, password changes, the Identification Form link, the Past Executive
Board if added on the live site) lives in the live database and `uploads/` folder. To carry it over:

1. On the **old** site: Admin › **Backup** › tick "Include the full-size original photos" › Download.
   The zip contains `instance/bct.db`, `uploads/` and `settings.ini`.
2. On the **new** server, install with Part A or B **but skip the import step** (A4).
3. Stop the app, then unzip the backup into the site folder (Part A: `~/bct-website`; Part B: `/opt/bct`,
   then `chown -R bct:bct /opt/bct`). Edit `settings.ini` if the port differs.
4. Start the app. The database upgrades itself automatically if it came from an older version.

---

## Admin accounts
- Sign in at `https://bandjouncommunitytexas.org/admin` (HTTPS required when `secure_cookies = true`).
- Initial accounts: **webadmin1** and **webadmin2** (passwords as provided to BCT; stored only as hashes).
  Change them after the first sign-in (My Account) and turn on two-step sign-in.
- Locked out / forgot password: `flask --app app reset-password webadmin1` (also clears lockout and 2-step).
- New admin: `flask --app app create-admin USERNAME --role editor`.

## Email (contact form)
Gmail account `bandjouncommunitytexas@gmail.com`: turn on 2-Step Verification, create an **App Password**,
paste it in Admin › Settings & Email (or `[smtp] password` in settings.ini), then **Send test**.

## Other CLI commands (venv active, in the site folder)
```bash
flask --app app import-content content --force     # wipe and re-import content (keeps users and messages)
flask --app app import-album /path/New_Event.zip   # add a photo album (one folder per album inside the zip)
flask --app app add-past-board                     # add the Past Executive Board (skips if it exists)
```

## Troubleshooting
| Symptom | Fix |
|---|---|
| Pages load but no photos/text | Content not imported — run A4 (`import-content content`) |
| Past Executive Boards page empty | `flask --app app add-past-board` |
| "Address already in use" | Another copy is running: `bash stop.sh`, then `bash start.sh` |
| "python: command not found" / exit 126 | Use `bash start.sh` (it uses `venv/bin/python`), or `source venv/bin/activate` first |
| Admin login reloads | Use https://, or set `secure_cookies = false` for http testing |
| 500/503 through Apache | Enable mod_proxy / mod_proxy_http; check the port in `.htaccess` |
| 502 with nginx + SELinux | `setsebool -P httpd_can_network_connect 1` |
| Photos missing (nginx) | `restorecon -R /opt/bct/uploads /opt/bct/static` |
| Test email fails | Use a Gmail App Password, port 587, STARTTLS |
