# Deployment Guide — Club Management → CapRover

## Files Added to Your Repo

| File | Purpose |
|------|---------|
| [Dockerfile](file:///c:/Users/aglan/OneDrive/Documents/finalclubmanagementphp/Dockerfile) | PHP 8.2 + Apache, `DocumentRoot` → `public/` |
| [captain-definition](file:///c:/Users/aglan/OneDrive/Documents/finalclubmanagementphp/captain-definition) | Tells CapRover to use the Dockerfile |
| [.dockerignore](file:///c:/Users/aglan/OneDrive/Documents/finalclubmanagementphp/.dockerignore) | Excludes [code.sql](file:///c:/Users/aglan/OneDrive/Documents/finalclubmanagementphp/code.sql), `prompts/`, orphaned files |
| [.env.production.example](file:///c:/Users/aglan/OneDrive/Documents/finalclubmanagementphp/.env.production.example) | Reference for env vars (never commit real values) |

---

## Step 1 — Push the New Files to GitLab

Run from your project folder on Windows (PowerShell):

```powershell
cd "C:\Users\aglan\OneDrive\Documents\finalclubmanagementphp"
git add Dockerfile captain-definition .dockerignore .env.production.example
git commit -m "chore: add CapRover deployment files"
git push origin main
```

---

## Step 2 — Create a MySQL App in CapRover (one-time)

1. Open `http://captain.caprover.al-arcade.com` → **One-Click Apps**
2. Search **MySQL** → Deploy it with app name **`club-db`**
3. Note down the root password CapRover shows you
4. Click **HTTP Settings** on `club-db` → **Do NOT expose** it publicly

Then run this SQL via CapRover's app exec or a phpMyAdmin one-click app:

```sql
CREATE DATABASE IF NOT EXISTS `club_management`
  CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE USER IF NOT EXISTS 'club_user'@'%'
  IDENTIFIED BY 'YOUR_STRONG_PASSWORD';

GRANT ALL PRIVILEGES ON `club_management`.* TO 'club_user'@'%';
FLUSH PRIVILEGES;
```

> [!IMPORTANT]
> Then import your full application schema SQL using phpMyAdmin or the MySQL CLI inside the container.

---

## Step 3 — Create the App in CapRover

1. CapRover Dashboard → **Apps** → **Create New App**
2. Name: `club-management`
3. **Do NOT** tick "Has Persistent Data"
4. Click **HTTP Settings** → Enable HTTPS (Let's Encrypt)

---

## Step 4 — Set Environment Variables

In the CapRover `club-management` app → **App Configs** tab → **Environmental Variables**:

| Key | Value |
|-----|-------|
| `APP_DEBUG` | `false` |
| `APP_URL` | `https://club-management.caprover.al-arcade.com` |
| `DB_HOST` | `srv-captain--club-db` |
| `DB_PORT` | `3306` |
| `DB_NAME` | `club_management` |
| `DB_USER` | `club_user` |
| `DB_PASS` | *(your strong password from Step 2)* |

> [!NOTE]
> `srv-captain--club-db` is CapRover's internal DNS name for the `club-db` app. No external port needed.

---

## Step 5 — Run the Deploy Script

Copy [deploy.sh](file:///C:/Users/aglan/.gemini/antigravity/brain/e5406d02-837e-4c40-85b0-ac275104d02a/deploy.sh) to your server via SSH, **edit the top variables**, then:

```bash
# On your CapRover Ubuntu server via SSH:
nano deploy.sh          # fill in the 6 config vars at the top
chmod +x deploy.sh
./deploy.sh
```

The script will:
1. Install Node.js + CapRover CLI if missing
2. Clone the GitLab repo fresh
3. Strip [code.sql](file:///c:/Users/aglan/OneDrive/Documents/finalclubmanagementphp/code.sql), `prompts/`, orphaned files from the build
4. Set env vars on the CapRover app via API
5. Enable HTTPS
6. Deploy the Docker image

---

## Step 6 — Alternative: Deploy Directly from GitLab CI (optional)

Add this `.gitlab-ci.yml` to your repo for automatic deploy on every push to `main`:

```yaml
deploy:
  stage: deploy
  image: node:20-alpine
  script:
    - npm install -g caprover
    - caprover deploy
        --caproverUrl $CAPROVER_URL
        --caproverPassword $CAPROVER_PASSWORD
        --appName club-management
        --branch main
  only:
    - main
```

Set `CAPROVER_URL` and `CAPROVER_PASSWORD` as **masked CI/CD variables** in GitLab → Settings → CI/CD → Variables.

---

## Post-Deploy Verification

- [ ] `https://club-management.caprover.al-arcade.com` loads the login page
- [ ] Login with admin account works
- [ ] Check CapRover app logs for PHP errors
- [ ] Confirm `storage/logs/` is writable (CapRover container has `www-data` perms set in Dockerfile)
- [ ] Upload a file via the member module to verify `storage/uploads/` works

> [!WARNING]
> If you need persistent file uploads to survive re-deploys, go to CapRover → **App Configs** → **Persistent Directories** and add `/var/www/html/storage/uploads` mounted to a volume.
