# Deployment Guide - lineupfrance.com (VPS cPanel)

Ce guide couvre le deploiement Laravel sur un VPS avec cPanel pour `lineupfrance.com`.

## 1) Prerequis serveur

- PHP 8.2+ (8.3 recommande)
- Extensions PHP: `mbstring`, `openssl`, `pdo_mysql`, `tokenizer`, `xml`, `ctype`, `json`, `bcmath`, `fileinfo`
- Composer 2.x
- MySQL/MariaDB
- SSL actif (AutoSSL cPanel ou certificat manuel)

## 2) Structure cible recommandee

Dans votre home cPanel:

```text
/home/<cpanel_user>/lineupfrance
├── current -> /home/<cpanel_user>/lineupfrance/releases/<release_id>
├── releases/
├── shared/
└── repo/
```

Le `DocumentRoot` du domaine `lineupfrance.com` doit pointer vers:

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

### Important: autoriser les verbes REST

Sur certains stacks cPanel/Apache, `PATCH` et `DELETE` sont bloques avant PHP.
Le projet force l'autorisation via:

- `/home/<cpanel_user>/lineupfrance/current/.htaccess`
- `/home/<cpanel_user>/lineupfrance/current/public/.htaccess`

Directive attendue:

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

## 3) Variables d'environnement production

1. Copier le fichier template:

```bash
cp .env.production.example .env
```

2. Completer au minimum:
- `APP_KEY` (generee via `php artisan key:generate --force`)
- Credentials MySQL (`DB_*`)
- SMTP (`MAIL_*`)
- Firebase (`FIREBASE_PROJECT`) + service account JSON selon `FIREBASE_CREDENTIALS`
- Push FCM (`LINEUP_FCM_LEGACY_SERVER_KEY`)
- URLs stores (`LINEUP_CLIENT_*`, `LINEUP_LINER_*`)

Si `FIREBASE_CREDENTIALS=storage/firebase/service-account.json`, deposer le JSON:

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

## 4) Premier deploiement (mode releases recommande)

Preparation:

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

Puis deploy:

```bash
./scripts/deploy_release_cpanel.sh
readlink /home/<cpanel_user>/lineupfrance/current
/home/<cpanel_user>/lineupfrance/current/scripts/preflight_cpanel.sh
```

## 5) Deploiements suivants

Utiliser le script versionne:

```bash
cd /home/<cpanel_user>/lineupfrance/repo
git fetch --all --prune
git checkout main
git pull --ff-only origin main
./scripts/deploy_release_cpanel.sh
readlink /home/<cpanel_user>/lineupfrance/current
/home/<cpanel_user>/lineupfrance/current/scripts/preflight_cpanel.sh
```

Option: lancer un smoke HTTP automatique en fin de deploiement:

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

Le script:
- active maintenance mode
- cree une nouvelle release horodatee
- installe les deps composer prod sur la release
- clear/rebuild caches Laravel
- execute les migrations
- relance l'application

Option simple (sans releases):

```bash
./scripts/deploy_cpanel.sh
```

## 6) Cron jobs cPanel

Ajouter ces taches cron dans cPanel.

Scheduler Laravel (toutes les minutes):

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

Queue worker sans daemon (toutes les minutes):

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

## 7) Verifications apres deploiement

- Landing: `https://lineupfrance.com/`
- Health: `https://lineupfrance.com/health`
- BO login: `https://lineupfrance.com/bo/login`
- API sample: `https://lineupfrance.com/api/auth/login`
- Smoke script: `./scripts/smoke_web.sh https://lineupfrance.com`

Gate unique pre-release (tests + preflight + smoke optionnel):

```bash
./scripts/release_gate.sh
# ou avec smoke
./scripts/release_gate.sh https://lineupfrance.com
```

## 8) Permissions

Les dossiers `storage/` et `bootstrap/cache/` doivent etre inscriptibles par l'utilisateur web.

## 9) Troubleshooting migration (important)

Erreur typique:

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

Cause:
- migrations non executees sur l'instance courante.

Fix:

```bash
cd /home/<cpanel_user>/lineupfrance/current
php artisan migrate --force
php artisan optimize:clear
php artisan optimize
```

Puis verifier:

```bash
/home/<cpanel_user>/lineupfrance/current/scripts/preflight_cpanel.sh
```

## 10) Rollback rapide

Automatique vers la release precedente:

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

Vers une release specifique:

```bash
/home/<cpanel_user>/lineupfrance/current/scripts/rollback_release_cpanel.sh /home/<cpanel_user>/lineupfrance/releases/<release_id>
```

## 11) Runbook rapide

Guide copier/coller:

- `docs/deployment/cpanel-runbook-copy-paste.md`
