104 lines
3.1 KiB
Markdown
104 lines
3.1 KiB
Markdown
# Déploiement Ferme (recette)
|
||
|
||
## 1) Premier déploiement
|
||
|
||
### Pré-requis système (Ubuntu)
|
||
1. Mettre à jour la machine
|
||
```bash
|
||
sudo apt update
|
||
sudo apt install -y software-properties-common ca-certificates curl gnupg unzip git nginx
|
||
```
|
||
2. Installer PHP 8.4 + FPM + extensions
|
||
```bash
|
||
sudo add-apt-repository -y ppa:ondrej/php
|
||
sudo apt update
|
||
sudo apt install -y \
|
||
php8.4 php8.4-fpm php8.4-cli php8.4-common \
|
||
php8.4-mbstring php8.4-xml php8.4-curl php8.4-intl \
|
||
php8.4-zip php8.4-gd php8.4-pgsql php8.4-opcache
|
||
```
|
||
3. Installer Composer
|
||
```bash
|
||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||
rm composer-setup.php
|
||
```
|
||
4. Installer Node via NVM
|
||
```bash
|
||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||
source ~/.bashrc
|
||
nvm install --lts
|
||
```
|
||
5. Installer PostgreSQL (si la DB est locale)
|
||
```bash
|
||
sudo apt install -y postgresql postgresql-contrib
|
||
sudo -u postgres psql
|
||
```
|
||
Dans psql :
|
||
```sql
|
||
CREATE USER ferme_user WITH PASSWORD 'motdepassefort';
|
||
CREATE DATABASE ferme OWNER ferme_user;
|
||
\q
|
||
```
|
||
|
||
### Déploiement applicatif
|
||
1. Cloner le repo
|
||
```bash
|
||
sudo mkdir -p /var/www
|
||
sudo git clone <repo> /var/www/ferme
|
||
sudo chown -R malio:malio /var/www/ferme
|
||
```
|
||
2. Variables d’environnement
|
||
- Backend : `/var/www/ferme/.env.local`
|
||
- `APP_ENV=prod`
|
||
- `APP_DEBUG=0`
|
||
- `APP_SECRET=...`
|
||
- `DATABASE_URL=postgresql://ferme_user:motdepassefort@127.0.0.1:5432/ferme?serverVersion=16&charset=utf8`
|
||
- `JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem`
|
||
- `JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem`
|
||
- `JWT_PASSPHRASE=...`
|
||
- `COOKIE_SECURE=1`
|
||
- `PONT_BASCULE_BYPASS=false`
|
||
- Frontend : `/var/www/ferme/frontend/.env`
|
||
- `NUXT_PUBLIC_APP_BASE=/`
|
||
- `NUXT_PUBLIC_API_BASE=/api`
|
||
3. Générer les clés JWT
|
||
```bash
|
||
cd /var/www/ferme
|
||
mkdir -p config/jwt
|
||
php bin/console lexik:jwt:generate-keypair
|
||
```
|
||
4. Config Nginx (sous-domaine)
|
||
```bash
|
||
sudo cp /var/www/ferme/deploy/nginx/ferme.conf /etc/nginx/sites-available/ferme.conf
|
||
sudo ln -s /etc/nginx/sites-available/ferme.conf /etc/nginx/sites-enabled/ferme.conf
|
||
sudo nginx -t && sudo systemctl reload nginx
|
||
```
|
||
6. Déployer l’app
|
||
```bash
|
||
cd /var/www/ferme
|
||
./scripts/deploy-native.sh
|
||
```
|
||
7. Vérifications
|
||
- Front : `http://ferme.malio-dev.fr/`
|
||
- API : `http://ferme.malio-dev.fr/api/users`
|
||
- Login : `POST http://ferme.malio-dev.fr/api/login_check`
|
||
|
||
## 2) Déployer une nouvelle version (app déjà en place)
|
||
|
||
1. Mettre à jour le code + build + migrations
|
||
```bash
|
||
cd /var/www/ferme
|
||
./scripts/deploy-native.sh
|
||
```
|
||
2. Si changement de conf Nginx
|
||
```bash
|
||
sudo cp /var/www/ferme/deploy/nginx/ferme.conf /etc/nginx/sites-available/ferme.conf
|
||
sudo nginx -t && sudo systemctl reload nginx
|
||
```
|
||
3. Si besoin, purger le cache Symfony
|
||
```bash
|
||
php /var/www/ferme/bin/console cache:clear --env=prod
|
||
php /var/www/ferme/bin/console cache:warmup --env=prod
|
||
```
|