313 lines
6.8 KiB
Markdown
313 lines
6.8 KiB
Markdown
# Inventory — Guide de Déploiement
|
|
|
|
Guide pour déployer l'application sur un serveur de production.
|
|
|
|
## Architecture de production
|
|
|
|
```
|
|
inventory.malio-dev.fr/ → Frontend Nuxt (fichiers statiques servis par Nginx)
|
|
inventory.malio-dev.fr/api → Backend Symfony (PHP-FPM derrière Nginx)
|
|
```
|
|
|
|
| Composant | Technologie | Emplacement serveur |
|
|
|-----------|-------------|---------------------|
|
|
| Backend | Symfony 8 + API Platform | `/var/www/Inventory/` |
|
|
| Frontend | Nuxt 4 (site statique) | `/var/www/Inventory/Inventory_frontend/.output/public/` |
|
|
| Base de données | PostgreSQL 16 | Base `inventory` |
|
|
|
|
### Schéma simplifié
|
|
|
|
```
|
|
Navigateur
|
|
↓ HTTPS
|
|
Nginx (reverse proxy)
|
|
├── /api/* → PHP-FPM (Symfony) → PostgreSQL
|
|
└── /* → Fichiers statiques (Nuxt build)
|
|
```
|
|
|
|
---
|
|
|
|
## Prérequis serveur
|
|
|
|
- **OS** : Ubuntu/Debian
|
|
- **PHP** : 8.4 avec extensions : pgsql, intl, zip, gd, mbstring, curl
|
|
- **Node.js** : 20+
|
|
- **Nginx**
|
|
- **PostgreSQL** : 16
|
|
- **Composer**
|
|
|
|
### Vérification des prérequis
|
|
|
|
```bash
|
|
php -v # PHP 8.4+
|
|
php -m | grep -E 'pgsql|intl|zip|gd|mbstring'
|
|
node -v # Node 20+
|
|
nginx -v
|
|
psql --version
|
|
composer --version
|
|
```
|
|
|
|
---
|
|
|
|
## Déploiement initial
|
|
|
|
### 1. Cloner le projet
|
|
|
|
```bash
|
|
cd /var/www
|
|
sudo git clone --recurse-submodules gitea@gitea.malio.fr:MALIO-DEV/Inventory.git Inventory
|
|
sudo chown -R malio:malio Inventory
|
|
cd Inventory
|
|
git checkout master
|
|
git submodule update --init --recursive
|
|
```
|
|
|
|
### 2. Créer la base de données
|
|
|
|
```bash
|
|
sudo -u postgres psql
|
|
|
|
CREATE DATABASE inventory OWNER ferme_user;
|
|
GRANT ALL PRIVILEGES ON DATABASE inventory TO ferme_user;
|
|
\q
|
|
```
|
|
|
|
Importer le dump :
|
|
```bash
|
|
# Copier le dump depuis le PC local
|
|
scp backup_v1.0.0_clean.sql malio@192.168.0.159:/tmp/
|
|
|
|
# Importer
|
|
psql -U ferme_user -h 127.0.0.1 -d inventory -f /tmp/backup_v1.0.0_clean.sql
|
|
```
|
|
|
|
### 3. Configurer le backend Symfony
|
|
|
|
```bash
|
|
cd /var/www/Inventory
|
|
|
|
# Installer les dépendances (sans les outils de dev)
|
|
composer install --no-dev --optimize-autoloader
|
|
|
|
# Créer le fichier de configuration locale
|
|
cat > .env.local << 'EOF'
|
|
APP_ENV=prod
|
|
APP_DEBUG=0
|
|
APP_SECRET=CHANGE_ME
|
|
|
|
DATABASE_URL="postgresql://ferme_user:fermerecette@127.0.0.1:5432/inventory?serverVersion=16"
|
|
|
|
CORS_ALLOW_ORIGIN='^https?://inventory\.malio-dev\.fr$'
|
|
EOF
|
|
|
|
# Générer un secret aléatoire
|
|
sed -i "s/CHANGE_ME/$(openssl rand -hex 32)/" .env.local
|
|
|
|
# Permissions pour le dossier var/ (cache, logs)
|
|
sudo chown -R www-data:www-data var/
|
|
sudo chmod -R 775 var/
|
|
|
|
# Vider le cache
|
|
php bin/console cache:clear --env=prod
|
|
|
|
# Appliquer les migrations (si première installation ou mise à jour)
|
|
php bin/console doctrine:migrations:migrate --no-interaction
|
|
```
|
|
|
|
### 4. Configurer le frontend Nuxt
|
|
|
|
```bash
|
|
cd /var/www/Inventory/Inventory_frontend
|
|
|
|
# Permissions
|
|
sudo chown -R malio:malio .
|
|
|
|
# Installer les dépendances
|
|
npm install
|
|
|
|
# Créer le fichier d'environnement
|
|
cat > .env << 'EOF'
|
|
NUXT_PUBLIC_API_BASE_URL=http://inventory.malio-dev.fr/api
|
|
EOF
|
|
|
|
# Générer le site statique
|
|
npx nuxi generate
|
|
```
|
|
|
|
### 5. Configurer Nginx
|
|
|
|
```bash
|
|
sudo nano /etc/nginx/sites-available/inventory
|
|
```
|
|
|
|
Contenu :
|
|
```nginx
|
|
server {
|
|
listen 80;
|
|
server_name inventory.malio-dev.fr;
|
|
|
|
# Gros fichiers (100MB max pour les uploads de documents)
|
|
client_max_body_size 100M;
|
|
client_body_timeout 300s;
|
|
send_timeout 300s;
|
|
|
|
access_log /var/log/nginx/inventory-access.log;
|
|
error_log /var/log/nginx/inventory-error.log;
|
|
|
|
# Backend Symfony — toutes les requêtes /api
|
|
location /api {
|
|
root /var/www/Inventory/public;
|
|
try_files $uri /index.php$is_args$args;
|
|
}
|
|
|
|
# PHP-FPM (exécute le code PHP)
|
|
location ~ ^/index\.php(/|$) {
|
|
fastcgi_pass unix:/run/php/php-fpm.sock;
|
|
fastcgi_split_path_info ^(.+\.php)(/.*)$;
|
|
include fastcgi_params;
|
|
fastcgi_param SCRIPT_FILENAME /var/www/Inventory/public/index.php;
|
|
fastcgi_param DOCUMENT_ROOT /var/www/Inventory/public;
|
|
fastcgi_read_timeout 300s;
|
|
internal;
|
|
}
|
|
|
|
# Frontend statique — tout le reste
|
|
location / {
|
|
root /var/www/Inventory/Inventory_frontend/.output/public;
|
|
index index.html;
|
|
try_files $uri $uri/ /index.html; # SPA fallback
|
|
}
|
|
}
|
|
```
|
|
|
|
Activer le site :
|
|
```bash
|
|
sudo ln -s /etc/nginx/sites-available/inventory /etc/nginx/sites-enabled/
|
|
sudo nginx -t # Vérifier la syntaxe
|
|
sudo systemctl reload nginx
|
|
```
|
|
|
|
### 6. Vérifier
|
|
|
|
```bash
|
|
curl http://inventory.malio-dev.fr # Frontend
|
|
curl http://inventory.malio-dev.fr/api # API (doc Swagger)
|
|
```
|
|
|
|
---
|
|
|
|
## Mises à jour
|
|
|
|
### Mettre à jour l'application
|
|
|
|
```bash
|
|
cd /var/www/Inventory
|
|
|
|
# Récupérer les changements
|
|
git pull
|
|
git submodule update --init --recursive
|
|
|
|
# Backend
|
|
composer install --no-dev --optimize-autoloader
|
|
php bin/console doctrine:migrations:migrate --no-interaction
|
|
php bin/console cache:clear --env=prod
|
|
sudo chown -R www-data:www-data var/
|
|
|
|
# Frontend
|
|
cd Inventory_frontend
|
|
npm install
|
|
npx nuxi generate
|
|
```
|
|
|
|
---
|
|
|
|
## Backup base de données
|
|
|
|
### Export (faire un backup)
|
|
|
|
```bash
|
|
pg_dump -U ferme_user -h 127.0.0.1 -d inventory \
|
|
--no-owner --no-acl --inserts --column-inserts \
|
|
--clean --if-exists > backup_inventory_$(date +%Y%m%d).sql
|
|
```
|
|
|
|
### Import (restaurer un backup)
|
|
|
|
```bash
|
|
psql -U ferme_user -h 127.0.0.1 -d inventory -f backup_inventory_YYYYMMDD.sql
|
|
```
|
|
|
|
---
|
|
|
|
## Troubleshooting
|
|
|
|
### Erreur 502 Bad Gateway
|
|
|
|
PHP-FPM ne tourne pas ou est crashé :
|
|
```bash
|
|
systemctl status php8.4-fpm
|
|
sudo systemctl restart php8.4-fpm
|
|
```
|
|
|
|
### Erreur 403 Forbidden
|
|
|
|
Problème de permissions sur les fichiers :
|
|
```bash
|
|
sudo chown -R www-data:www-data /var/www/Inventory/var/
|
|
sudo chmod -R 775 /var/www/Inventory/var/
|
|
```
|
|
|
|
### Erreur API "No route found"
|
|
|
|
Le cache Symfony est probablement périmé :
|
|
```bash
|
|
php /var/www/Inventory/bin/console cache:clear --env=prod
|
|
```
|
|
|
|
### Frontend ne se met pas à jour
|
|
|
|
Les fichiers statiques sont en cache. Rebuilder :
|
|
```bash
|
|
cd /var/www/Inventory/Inventory_frontend
|
|
rm -rf .output
|
|
npx nuxi generate
|
|
```
|
|
|
|
### L'API retourne 401 sur toutes les requêtes
|
|
|
|
La session PHP ne se crée pas correctement. Vérifier :
|
|
```bash
|
|
# Vérifier que le dossier de sessions existe et est accessible
|
|
ls -la /var/lib/php/sessions/
|
|
# Ou vérifier les logs Symfony
|
|
tail -f /var/www/Inventory/var/log/prod.log
|
|
```
|
|
|
|
---
|
|
|
|
## Commandes utiles en production
|
|
|
|
```bash
|
|
# Logs Nginx
|
|
tail -f /var/log/nginx/inventory-error.log
|
|
tail -f /var/log/nginx/inventory-access.log
|
|
|
|
# Logs Symfony
|
|
tail -f /var/www/Inventory/var/log/prod.log
|
|
|
|
# Vider le cache Symfony
|
|
php /var/www/Inventory/bin/console cache:clear --env=prod
|
|
|
|
# Rebuild frontend
|
|
cd /var/www/Inventory/Inventory_frontend && npx nuxi generate
|
|
|
|
# Status des services
|
|
systemctl status php8.4-fpm
|
|
systemctl status nginx
|
|
systemctl status postgresql
|
|
|
|
# Redémarrer les services
|
|
sudo systemctl restart php8.4-fpm
|
|
sudo systemctl reload nginx
|
|
```
|