#!/bin/bash # Basé sur un travail de Cédric Abonnel / Cédrix sous licence CC BY-NC 4.0 # Importer les fonctions communes source "$(dirname "$0")/../common/common_utils.sh" # Vérifier si le script est exécuté en root check_root # Mise à jour du système update_system PASS_FILE=~/mariadb_root_password.txt DEBIAN_CNF=/etc/mysql/debian.cnf MARIADB_CNF=/etc/mysql/mariadb.conf.d/50-server.cnf echo "=== Installation de MariaDB ===" apt install -y mariadb-server mariadb-client echo "=== Activation et démarrage de MariaDB ===" systemctl enable mariadb systemctl start mariadb echo "=== Configuration du bind-address pour bloquer les connexions externes ===" if grep -q "^bind-address" $MARIADB_CNF; then sed -i 's/^bind-address.*/bind-address = 127.0.0.1/' $MARIADB_CNF else echo "bind-address = 127.0.0.1" >> $MARIADB_CNF fi echo "=== Activation du log binaire et purge automatique des anciens logs ===" if ! grep -q "^log-bin" "$MARIADB_CNF"; then cat >> "$MARIADB_CNF" < "$PASS_FILE" chmod 600 "$PASS_FILE" echo "Mot de passe root sauvegardé dans $PASS_FILE." fi fi fi echo "=== Sécurisation de MariaDB ===" mysql -u root -p"$DB_ROOT_PASSWORD" < /etc/mysql/debian.cnf </dev/null 2>&1; then PHP_VERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') echo "PHP version détectée : $PHP_VERSION" echo "=== Installation de php-mysql pour PHP $PHP_VERSION ===" apt install -y php${PHP_VERSION}-mysql echo "=== Redémarrage d'Apache si installé ===" if systemctl list-units --type=service | grep -q apache2; then systemctl restart apache2 echo "Apache redémarré" fi echo "=== Redémarrage de PHP-FPM si installé ===" if systemctl list-units --type=service | grep -q php${PHP_VERSION}-fpm; then systemctl restart php${PHP_VERSION}-fpm echo "PHP-FPM redémarré" fi else echo "PHP n'est pas installé. Installation de MariaDB terminée sans liaison PHP." fi echo "=== Fin de l'installation et sécurisation de MariaDB ==="