# Runbook cPanel - Copier/Coller (lineupfrance.com)

Ce runbook est la version operationnelle courte pour deployer vite et proprement.

## 0) Variables a definir

Remplacer ces placeholders dans les commandes:

- `<CPANEL_USER>`
- `<GIT_REPO_URL>`
- `<GIT_BRANCH>` (ex: `main`)

## 1) cPanel: domaine et SSL

1. Dans cPanel, ajouter `lineupfrance.com` (ou verifier qu'il existe).
2. Activer AutoSSL.
3. Definir `DocumentRoot` du domaine sur:

```text
/home/<CPANEL_USER>/lineupfrance/current/public
```

4. Verifier que les `.htaccess` du projet autorisent les verbes REST:

```apache
<IfModule mod_allowmethods.c>
    AllowMethods reset GET POST PUT PATCH DELETE OPTIONS HEAD
</IfModule>
```

## 2) cPanel: base MySQL

Creer:
- une base MySQL
- un utilisateur MySQL
- grant `ALL PRIVILEGES` sur la base

Noter `DB_DATABASE`, `DB_USERNAME`, `DB_PASSWORD`.

## 3) Premier setup serveur (Terminal cPanel)

```bash
mkdir -p /home/<CPANEL_USER>/lineupfrance/{releases,shared,repo}
cd /home/<CPANEL_USER>/lineupfrance/repo
git clone --branch <GIT_BRANCH> <GIT_REPO_URL> .
cp .env.production.example .env
php artisan key:generate --force
```

Editer `.env` puis verifier au minimum:
- `APP_URL=https://lineupfrance.com`
- `APP_DEBUG=false`
- `DB_*`
- `MAIL_*`
- `FIREBASE_PROJECT` et `FIREBASE_CREDENTIALS` (service-account JSON present)
- `LINEUP_FCM_LEGACY_SERVER_KEY`
- `LINEUP_CLIENT_*` et `LINEUP_LINER_*`

Si `FIREBASE_CREDENTIALS=storage/firebase/service-account.json`:

```bash
mkdir -p /home/<CPANEL_USER>/lineupfrance/shared/storage/firebase
# uploader service-account.json dans ce dossier
```

## 4) Premier deploy release + symlink

```bash
cd /home/<CPANEL_USER>/lineupfrance/repo
./scripts/deploy_release_cpanel.sh
readlink /home/<CPANEL_USER>/lineupfrance/current
/home/<CPANEL_USER>/lineupfrance/current/scripts/preflight_cpanel.sh
```

## 5) Cron jobs cPanel

Dans cPanel > Cron Jobs, ajouter:

```bash
* * * * * cd /home/<CPANEL_USER>/lineupfrance/current && php artisan schedule:run >> /dev/null 2>&1
```

```bash
* * * * * cd /home/<CPANEL_USER>/lineupfrance/current && php artisan queue:work --stop-when-empty --queue=default >> /dev/null 2>&1
```

## 6) Deploy quotidien (nouvelle version)

```bash
cd /home/<CPANEL_USER>/lineupfrance/repo
git fetch --all --prune
git checkout <GIT_BRANCH>
git pull --ff-only origin <GIT_BRANCH>
./scripts/deploy_release_cpanel.sh
readlink /home/<CPANEL_USER>/lineupfrance/current
/home/<CPANEL_USER>/lineupfrance/current/scripts/preflight_cpanel.sh
/home/<CPANEL_USER>/lineupfrance/current/scripts/smoke_web.sh https://lineupfrance.com
```

Option en un seul passage (post-deploy smoke automatique):

```bash
LINEUP_SMOKE_URL=https://lineupfrance.com ./scripts/deploy_release_cpanel.sh
```

## 7) Rollback rapide

Automatique vers la release precedente:

```bash
/home/<CPANEL_USER>/lineupfrance/current/scripts/rollback_release_cpanel.sh
```

Rollback vers une release specifique:

```bash
/home/<CPANEL_USER>/lineupfrance/current/scripts/rollback_release_cpanel.sh /home/<CPANEL_USER>/lineupfrance/releases/<RELEASE_ID>
```

## 8) Smoke checks

```bash
curl -s https://lineupfrance.com/health
curl -I https://lineupfrance.com/bo/login
```

Attendu:
- `/health` retourne `{"status":"ok","service":"lineup-france-web"}`
- `/bo/login` retourne `200`

## 9) Fix rapide erreur SQL migrations manquantes

Si vous voyez:

```text
SQLSTATE[HY000]: ... no such table: user_payment_methods
```

Executer:

```bash
cd /home/<CPANEL_USER>/lineupfrance/current
php artisan migrate --force
php artisan optimize:clear
php artisan optimize
/home/<CPANEL_USER>/lineupfrance/current/scripts/preflight_cpanel.sh
```
