#!/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 # Définition des couleurs pour un affichage clair GREEN="\e[32m" YELLOW="\e[33m" RED="\e[31m" RESET="\e[0m" echo -e "${YELLOW}Mise à jour des paquets...${RESET}" apt update && apt upgrade -y || { echo -e "${RED}Échec de la mise à jour des paquets${RESET}"; exit 1; } # Détection de la version de Debian VERSION=$(lsb_release -sc) SUPPORTED_VERSIONS=("buster" "bullseye" "bookworm") if [[ ! " ${SUPPORTED_VERSIONS[@]} " =~ " ${VERSION} " ]]; then echo -e "${RED}Version de Debian non supportée : $VERSION${RESET}" exit 1 fi echo -e "${GREEN}Version de Debian détectée : $VERSION${RESET}" # Vérification de l'existence du dépôt Sury if ! grep -q "packages.sury.org" /etc/apt/sources.list.d/php.list 2>/dev/null; then echo -e "${YELLOW}Ajout du dépôt Sury pour PHP...${RESET}" apt install -y ca-certificates apt-transport-https software-properties-common || { echo -e "${RED}Échec de l'installation des paquets nécessaires${RESET}"; exit 1; } wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg || { echo -e "${RED}Échec du téléchargement de la clé GPG de Sury${RESET}"; exit 1; } echo "deb https://packages.sury.org/php/ $VERSION main" | tee /etc/apt/sources.list.d/php.list apt update else echo -e "${GREEN}Le dépôt Sury est déjà installé.${RESET}" fi # Définition de la version PHP souhaitée PHP_VERSION="8.3" # Vérification de l'installation de PHP echo -e "${YELLOW}Installation de PHP $PHP_VERSION et des modules courants...${RESET}" apt install -y php$PHP_VERSION php$PHP_VERSION-cli php$PHP_VERSION-fpm \ php$PHP_VERSION-mysql php$PHP_VERSION-curl php$PHP_VERSION-gd \ php$PHP_VERSION-mbstring php$PHP_VERSION-xml php$PHP_VERSION-zip \ php$PHP_VERSION-bcmath php$PHP_VERSION-soap php$PHP_VERSION-intl \ php$PHP_VERSION-readline php$PHP_VERSION-ldap php$PHP_VERSION-imagick || { echo -e "${RED}Échec de l'installation de PHP${RESET}"; exit 1; } # Vérification si Apache est installé et installation du module PHP si nécessaire if systemctl list-units --type=service --all | grep -q "apache2.service"; then echo -e "${YELLOW}Apache détecté. Installation de libapache2-mod-php${RESET}" apt install -y libapache2-mod-php$PHP_VERSION || { echo -e "${RED}Échec de l'installation de libapache2-mod-php${RESET}"; exit 1; } echo -e "${YELLOW}Redémarrage d'Apache...${RESET}" systemctl restart apache2 || { echo -e "${RED}Échec du redémarrage d'Apache${RESET}"; exit 1; } fi # Configuration de PHP-FPM si ce n'est pas déjà fait PHP_INI="/etc/php/$PHP_VERSION/fpm/php.ini" if grep -q "memory_limit = 512M" "$PHP_INI"; then echo -e "${GREEN}Configuration de PHP-FPM déjà optimisée.${RESET}" else echo -e "${YELLOW}Configuration de PHP-FPM...${RESET}" sed -i 's/memory_limit = .*/memory_limit = 512M/' "$PHP_INI" sed -i 's/upload_max_filesize = .*/upload_max_filesize = 100M/' "$PHP_INI" sed -i 's/post_max_size = .*/post_max_size = 100M/' "$PHP_INI" sed -i 's/max_execution_time = .*/max_execution_time = 300/' "$PHP_INI" echo -e "${YELLOW}Redémarrage de PHP-FPM...${RESET}" systemctl restart php$PHP_VERSION-fpm || { echo -e "${RED}Échec du redémarrage de PHP-FPM${RESET}"; exit 1; } fi # Vérification des modules PHP installés echo -e "${GREEN}Modules PHP installés :${RESET}" php -m # Test de la configuration Apache if systemctl is-active --quiet apache2; then echo -e "${YELLOW}Vérification du support de PHP par Apache...${RESET}" echo "" > /var/www/html/info.php chown www-data:www-data /var/www/html/info.php chmod 644 /var/www/html/info.php echo -e "${GREEN}Vous pouvez tester PHP en accédant à : http:///info.php${RESET}" fi echo -e "${GREEN}Installation terminée avec succès ! 🚀${RESET}"