Configuration Bookstak avec Caddy
Configuration Debian 10
Prérequis :
- Debian 10
- Caddy 2
- MariaDB
- PHP 7.4
Installez les prérequis
apt update && apt full-upgrade -y
apt install -y git unzip curl mariadb-server php7.4 php7.4-cli php7.4-fpm php7.4-tidy php7.4-curl php7.4-ldap php7.4-mcrypt php7.4-gd php7.4-xml php7.4-zip php7.4-mysql php7.4-mbstring php7.4-common
Supprimer le démarrage d'apache et Nginx
Question ?
Pourquoi apache est il installé avec apt install php-7.4 ?
Pourquoi nginx est il installé avec apt install php-7.4-fpm ?
Je m'attend que apt installe JUSTE php7.4 ...
Désactiver apache2 et nginx au démarrage du serveur OU supprimer les supprimer du serveur ( attention aux dépendances !)
systemctl disable --now apache2
systemctl disable --now nginx
apt remove --purge apache2
apt remove --purge nginx
Création base de donnée pour bookstack
mysql -u root
CREATE DATABASE bookstackDB;
GRANT ALL ON bookstackDB.* TO 'bookstack' IDENTIFIED BY 'TheBookStackADM';
FLUSH PRIVILEGES;
Configuration serveur web Caddy2
Création utilisateur caddy
groupadd --system caddy
useradd --system \
--gid caddy \
--create-home \
--home-dir /var/lib/caddy \
--shell /usr/sbin/nologin \
--comment "Caddy web server" \
caddy
Fichier de démarrage Systemd
Bon à savoir !
Emplacement: /etc/systemd/system
Nom du fichier: caddy.service
# caddy.service
# # For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
Activer le fichier de démarrage et lancer le service
systemctl daemon-reload
systemctl enable caddy
systemctl start caddy
Fichier Caddyfile
Bon à savoir !
Emplacement: /etc/caddy/
Nom du fichier: Caddyfile
# On met le nom de domaine que l'on veut rendre public HTTPS est actif automatiquement via Let's Encrypt
nomdedomaine.fr
# On met l'emplacement des fichier web
root * /var/www/bookstack/public
# On active la compression
encode zstd gzip
try_files# {path}On /index.php?{query}&p={path}pointe vers le service PHP
php_fastcgi unix//run/php/php7.4-fpm.sock
# On sert des fichiers statiques ( dont le fameux index.html index.php etc... )
file_server
Appliquez les bon droits aux fichiers web pour caddy
chown -R www-data:www-data /var/www/bookstack
Configuration BookStack
Installation fichier bookstack
Se positionner dans /var/www/
cd /var/www
Cloner les fichier source du projet bookstack
git clone https://github.com/BookStackApp/BookStack.git --branch release --single-branch
Renommer le fichier .env.example en .env
mv /var/www/bookstack/.env.example /var/www/bookstack/.env
Modifier le fichier .env
Emplacement: /var/www/bookstack
Nom du fichier: .env
Bon à savoir !
Modifier les parties suivantes
- APP_URL
- DB_HOST
- DB_DATABASE
- DB_USERNAME
- DB_PASSWORD
# Application key
# Used for encryption where needed.
# Run `php artisan key:generate` to generate a valid key.
APP_KEY=
# Application URL
# Remove the hash below and set a URL if using BookStack behind
# a proxy, if using a third-party authentication option.
# This must be the root URL that you want to host BookStack on.
# All URL's in BookStack will be generated using this value.
APP_URL=https://serveur.domaine.fr
# Database details
DB_HOST=localhost
DB_DATABASE=bookstack
DB_USERNAME=bookstack
DB_PASSWORD=LeFameuxMotDePasse
Installer composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
Installer les dépendances via composer
Bon à savoir
Exécutez les commandes suivantes dans /var/www/bookstack
cd /var/www/bookstack
composer install --no-dev
php artisan key:generate
php artisan migrate
Appliquez les bon droits aux fichiers web pour caddy
chown -R www-data:www-data /var/www/bookstack
Gestion service et log
Service Caddy
Lancer, redémarrer et arreter le service
systemctl start caddy
systemctl reload caddy
systemctl stop caddy
Voir les logs
systemctl status caddy
journalctl -u caddy