Commit d2be0f62 authored by AGLANPC\aglan's avatar AGLANPC\aglan

yfghjfcg

parent fd6f8339
# 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.
#!/usr/bin/env bash
# =============================================================================
# Club Management System — Full CapRover Deploy Script
# Run this on a fresh Ubuntu 22.04 SSH session on your CapRover server,
# OR from any machine that has SSH + internet access.
#
# Usage:
# chmod +x deploy.sh
# ./deploy.sh
# =============================================================================
set -e
# ─── CONFIGURATION ──────────────────────────────────────────────────────────
# Edit these before running
CAPROVER_URL="http://captain.caprover.al-arcade.com" # Your CapRover dashboard URL
CAPROVER_PASSWORD="Alarcade123#" # CapRover admin password
APP_NAME="club-management-club" # The CapRover app name to create/update
GITLAB_REPO="http://gitlab.caprover.al-arcade.com/root/finalclubmanagementphp.git"
GITLAB_USER="root"
GITLAB_TOKEN="vHATWUzqfUC1nkXkGkai" # GitLab → Settings → Access Tokens
# DB config — your existing database server
DB_HOST="srv-captain--mysql-db" # e.g. 192.168.1.10 or db.al-arcade.com
DB_PORT="3306"
DB_NAME="club_management"
DB_USER="root"
DB_PASS="Alarcade123#"
APP_URL="https://${APP_NAME}.caprover.al-arcade.com" # or your custom domain
# ─── COLORS ──────────────────────────────────────────────────────────────────
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*"; exit 1; }
# ─── 1. PREREQUISITES ────────────────────────────────────────────────────────
info "Checking prerequisites..."
if ! command -v node &>/dev/null; then
info "Installing Node.js 20..."
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
node -v
if ! command -v caprover &>/dev/null; then
info "Installing CapRover CLI..."
sudo npm install -g caprover
fi
caprover --version
if ! command -v git &>/dev/null; then
sudo apt-get update && sudo apt-get install -y git
fi
# ─── 2. CLONE OR PULL THE REPO ───────────────────────────────────────────────
DEPLOY_DIR="/tmp/club_deploy_$(date +%s)"
info "Cloning repository to ${DEPLOY_DIR}..."
git clone "http://${GITLAB_USER}:${GITLAB_TOKEN}@$(echo $GITLAB_REPO | sed 's|http://||')" "$DEPLOY_DIR"
cd "$DEPLOY_DIR"
# ─── 3. SAFETY CLEANUP ───────────────────────────────────────────────────────
info "Removing sensitive dev files..."
rm -f code.sql
rm -f core/App_112.php core/Database_110.php core/View_111.php core/helpers_109.php
rm -rf prompts/
# ─── 4. CREATE CAPROVER APP (idempotent) ─────────────────────────────────────
info "Logging in to CapRover at ${CAPROVER_URL}..."
caprover login \
--caproverUrl "$CAPROVER_URL" \
--caproverPassword "$CAPROVER_PASSWORD" \
--name "production"
info "Creating CapRover app '${APP_NAME}' (skips if already exists)..."
caprover api \
--caproverUrl "$CAPROVER_URL" \
--caproverPassword "$CAPROVER_PASSWORD" \
--path "/v2/user/apps/appDefinitions/register" \
--method "POST" \
--data "{\"appName\":\"${APP_NAME}\",\"hasPersistentData\":false}" 2>/dev/null || true
# ─── 5. SET ENVIRONMENT VARIABLES ON THE CAPROVER APP ───────────────────────
info "Setting environment variables..."
ENV_VARS=$(cat <<EOF
[
{"key":"APP_DEBUG", "value":"false"},
{"key":"APP_URL", "value":"${APP_URL}"},
{"key":"DB_HOST", "value":"${DB_HOST}"},
{"key":"DB_PORT", "value":"${DB_PORT}"},
{"key":"DB_NAME", "value":"${DB_NAME}"},
{"key":"DB_USER", "value":"${DB_USER}"},
{"key":"DB_PASS", "value":"${DB_PASS}"}
]
EOF
)
caprover api \
--caproverUrl "$CAPROVER_URL" \
--caproverPassword "$CAPROVER_PASSWORD" \
--path "/v2/user/apps/appDefinitions/update" \
--method "POST" \
--data "{\"appName\":\"${APP_NAME}\",\"envVars\":${ENV_VARS}}"
info "Environment variables set."
# ─── 6. ENABLE HTTPS ON THE APP ──────────────────────────────────────────────
info "Enabling HTTPS (Let's Encrypt)..."
caprover api \
--caproverUrl "$CAPROVER_URL" \
--caproverPassword "$CAPROVER_PASSWORD" \
--path "/v2/user/apps/appDefinitions/enablebasedomainssl" \
--method "POST" \
--data "{\"appName\":\"${APP_NAME}\"}" 2>/dev/null || warn "HTTPS may already be enabled or domain not set yet."
# ─── 7. DEPLOY ───────────────────────────────────────────────────────────────
info "Packaging and deploying to CapRover..."
caprover deploy \
--caproverUrl "$CAPROVER_URL" \
--caproverPassword "$CAPROVER_PASSWORD" \
--appName "$APP_NAME" \
--branch "main"
info "Deploy complete!"
echo ""
echo "─────────────────────────────────────────────"
echo " App URL : ${APP_URL}"
echo " DB Pass : ${DB_PASS} ← SAVE THIS"
echo "─────────────────────────────────────────────"
echo ""
info "App is pointing to your existing DB at: ${DB_HOST}/${DB_NAME}"
warn "Make sure your DB server allows connections from the CapRover container IP."
# ─── CLEANUP ─────────────────────────────────────────────────────────────────
cd /tmp && rm -rf "$DEPLOY_DIR"
info "Temp files cleaned up."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment