6.7 KiB
6.7 KiB
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/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
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
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
sudo -u postgres psql
CREATE DATABASE inventory OWNER ferme_user;
GRANT ALL PRIVILEGES ON DATABASE inventory TO ferme_user;
\q
Importer le dump :
# 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
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
cd /var/www/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
sudo nano /etc/nginx/sites-available/inventory
Contenu :
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/frontend/.output/public;
index index.html;
try_files $uri $uri/ /index.html; # SPA fallback
}
}
Activer le site :
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
curl http://inventory.malio-dev.fr # Frontend
curl http://inventory.malio-dev.fr/api # API (doc Swagger)
Mises à jour
Mettre à jour l'application
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 frontend
npm install
npx nuxi generate
Backup base de données
Export (faire un backup)
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)
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é :
systemctl status php8.4-fpm
sudo systemctl restart php8.4-fpm
Erreur 403 Forbidden
Problème de permissions sur les fichiers :
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é :
php /var/www/Inventory/bin/console cache:clear --env=prod
Frontend ne se met pas à jour
Les fichiers statiques sont en cache. Rebuilder :
cd /var/www/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 :
# 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
# 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/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