-
Notifications
You must be signed in to change notification settings - Fork 0
Production Apache
Ce guide decrit une mise en production de Forum PHP sur un serveur Linux (Ubuntu 22.04 LTS ou equivalent) avec Apache et PHP-FPM. Adaptez les chemins et les noms de paquets si vous utilisez une autre distribution.
Mettez le systeme a jour et installez les paquets necessaires :
sudo apt update && sudo apt upgrade -y
sudo apt install -y apache2 mysql-server git unzip curlInstallez PHP 8.3 et les extensions requises (via le depot PPA ondrej/php si votre distribution ne fournit pas PHP 8.3 nativement) :
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php8.3 php8.3-fpm php8.3-mysql php8.3-mbstring php8.3-xml php8.3-curl php8.3-gd php8.3-bcmath php8.3-cliInstallez Composer :
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composerInstallez Node.js 18+ (via NodeSource par exemple) :
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejssudo mkdir -p /var/www/forum-php
sudo chown $USER:$USER /var/www/forum-php
git clone https://github.com/Cut0x/forum-php.git /var/www/forum-php
cd /var/www/forum-phpInstallez les dependances en mode production (sans les paquets de developpement) :
composer install --no-dev --optimize-autoloader
npm ci
npm run buildcp .env.example .env
php artisan key:generateEditez .env pour la production :
APP_ENV=production
APP_DEBUG=false
APP_URL=https://votre-domaine.tld
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=forum
DB_USERNAME=forum_user
DB_PASSWORD=mot_de_passe_fort
MAIL_MAILER=smtp
MAIL_HOST=votre-serveur-smtp
MAIL_PORT=587
MAIL_USERNAME=...
MAIL_PASSWORD=...
MAIL_FROM_ADDRESS=no-reply@votre-domaine.tld
MAIL_FROM_NAME="${APP_NAME}"
Creez la base de donnees et un utilisateur MySQL dedie :
CREATE DATABASE forum CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'forum_user'@'localhost' IDENTIFIED BY 'mot_de_passe_fort';
GRANT ALL PRIVILEGES ON forum.* TO 'forum_user'@'localhost';
FLUSH PRIVILEGES;php artisan migrate --force
php artisan storage:link
php artisan app:create-adminLe serveur web doit pouvoir ecrire dans storage/ et bootstrap/cache/ :
sudo chown -R www-data:www-data /var/www/forum-php
sudo find /var/www/forum-php/storage -type d -exec chmod 775 {} \;
sudo find /var/www/forum-php/bootstrap/cache -type d -exec chmod 775 {} \;php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cacheA rejouer apres chaque mise a jour du code ou du .env. En cas de comportement inattendu apres une mise a jour, videz d'abord ces caches avec php artisan optimize:clear avant de les regenerer.
Activez les modules necessaires :
sudo a2enmod rewrite headers proxy_fcgi setenvif
sudo a2enconf php8.3-fpmCreez /etc/apache2/sites-available/forum-php.conf :
<VirtualHost *:80>
ServerName votre-domaine.tld
DocumentRoot /var/www/forum-php/public
<Directory /var/www/forum-php/public>
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/forum-php-error.log
CustomLog ${APACHE_LOG_DIR}/forum-php-access.log combined
</VirtualHost>Le fichier public/.htaccess fourni par Laravel gere deja la reecriture d'URL vers index.php : aucune regle supplementaire n'est necessaire tant que mod_rewrite est actif et AllowOverride All est defini.
Activez le site et rechargez Apache :
sudo a2ensite forum-php.conf
sudo systemctl reload apache2Utilisez Certbot pour obtenir et configurer automatiquement un certificat Let's Encrypt :
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d votre-domaine.tldCertbot modifie automatiquement le virtual host pour ecouter en HTTPS et met en place le renouvellement automatique du certificat.
php artisan testOuvrez https://votre-domaine.tld dans un navigateur, verifiez l'inscription, la creation d'un sujet, et la connexion au panel admin avec le compte cree a l'etape 4.
Pour deployer une nouvelle version du code :
cd /var/www/forum-php
git pull
composer install --no-dev --optimize-autoloader
npm ci && npm run build
php artisan migrate --force
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cachePour toute erreur rencontree pendant le deploiement, consultez la page Depannage.
Forum PHP
Installation
Production
Utilisation
Autres