compatibilité Trixie - Debian 13 uniquement
This commit is contained in:
@@ -1,165 +1,103 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Basé sur un travail de Cédric Abonnel / Cédrix sous licence CC BY-NC 4.0
|
# 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"
|
source "$(dirname "$0")/../common/common_utils.sh"
|
||||||
|
|
||||||
# Vérifier si le script est exécuté en root
|
|
||||||
check_root
|
check_root
|
||||||
|
|
||||||
# Définition des couleurs pour un affichage clair
|
|
||||||
GREEN="\e[32m"
|
GREEN="\e[32m"
|
||||||
YELLOW="\e[33m"
|
YELLOW="\e[33m"
|
||||||
RED="\e[31m"
|
RED="\e[31m"
|
||||||
RESET="\e[0m"
|
RESET="\e[0m"
|
||||||
|
|
||||||
echo -e "${YELLOW}Mise à jour des paquets...${RESET}"
|
echo -e "${YELLOW}Mise à jour du système...${RESET}"
|
||||||
apt update && apt upgrade -y || { echo -e "${RED}Échec de la mise à jour des paquets${RESET}"; exit 1; }
|
apt update && apt upgrade -y
|
||||||
|
|
||||||
# Détection de la version de Debian
|
|
||||||
VERSION=$(lsb_release -sc)
|
VERSION=$(lsb_release -sc)
|
||||||
SUPPORTED_VERSIONS=("buster" "bullseye" "bookworm")
|
SUPPORTED_VERSIONS=("trixie")
|
||||||
|
|
||||||
TIMEZONE=$(timedatectl show --value --property=Timezone)
|
TIMEZONE=$(timedatectl show --value --property=Timezone)
|
||||||
|
TIMEZONE=${TIMEZONE:-UTC}
|
||||||
|
|
||||||
if [[ ! " ${SUPPORTED_VERSIONS[@]} " =~ " ${VERSION} " ]]; then
|
if [[ ! " ${SUPPORTED_VERSIONS[@]} " =~ " ${VERSION} " ]]; then
|
||||||
echo -e "${RED}Version de Debian non supportée : $VERSION${RESET}"
|
echo -e "${RED}Version non supportée : $VERSION${RESET}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}Version de Debian détectée : $VERSION${RESET}"
|
# Dépôt Sury (Format moderne avec signed-by pour Trixie)
|
||||||
|
|
||||||
# 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
|
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 curl
|
||||||
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; }
|
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
|
||||||
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 [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $VERSION main" > /etc/apt/sources.list.d/php.list
|
||||||
echo "deb https://packages.sury.org/php/ $VERSION main" | tee /etc/apt/sources.list.d/php.list
|
|
||||||
apt update
|
apt update
|
||||||
else
|
|
||||||
echo -e "${GREEN}Le dépôt Sury est déjà installé.${RESET}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Définition de la version PHP souhaitée
|
|
||||||
PHP_VERSION="8.3"
|
PHP_VERSION="8.3"
|
||||||
|
echo -e "${YELLOW}Installation de PHP $PHP_VERSION...${RESET}"
|
||||||
|
|
||||||
PHP_INI_CLI="/etc/php/${PHP_VERSION}/cli/php.ini"
|
|
||||||
PHP_INI_APACHE="/etc/php/${PHP_VERSION}/apache2/php.ini"
|
|
||||||
|
|
||||||
# Vérification de l'installation de PHP
|
|
||||||
echo -e "${YELLOW}Installation de PHP $PHP_VERSION et des modules courants...${RESET}"
|
|
||||||
|
|
||||||
# Base des modules PHP à installer
|
|
||||||
PHP_MODULES=(
|
PHP_MODULES=(
|
||||||
php${PHP_VERSION}
|
php${PHP_VERSION} php${PHP_VERSION}-cli php${PHP_VERSION}-fpm php${PHP_VERSION}-common
|
||||||
php${PHP_VERSION}-cli
|
php${PHP_VERSION}-curl php${PHP_VERSION}-gd php${PHP_VERSION}-mbstring php${PHP_VERSION}-xml
|
||||||
php${PHP_VERSION}-fpm
|
php${PHP_VERSION}-zip php${PHP_VERSION}-bcmath php${PHP_VERSION}-soap php${PHP_VERSION}-intl
|
||||||
php${PHP_VERSION}-curl
|
php${PHP_VERSION}-readline php${PHP_VERSION}-ldap php${PHP_VERSION}-imagick php${PHP_VERSION}-gmp
|
||||||
php${PHP_VERSION}-gd
|
php${PHP_VERSION}-apcu php${PHP_VERSION}-opcache php${PHP_VERSION}-sqlite3
|
||||||
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
|
|
||||||
php${PHP_VERSION}-exif
|
|
||||||
php${PHP_VERSION}-gmp
|
|
||||||
php${PHP_VERSION}-apcu
|
|
||||||
php${PHP_VERSION}-opcache
|
|
||||||
php${PHP_VERSION}-sqlite3
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Vérification MySQL / MariaDB
|
dpkg -l | grep -qE 'mysql-server|mariadb-server' && PHP_MODULES+=(php${PHP_VERSION}-mysql)
|
||||||
if dpkg -l | grep -qE 'mysql-server|mariadb-server'; then
|
dpkg -l | grep -q postgresql && PHP_MODULES+=(php${PHP_VERSION}-pgsql)
|
||||||
echo -e "${GREEN}MySQL/MariaDB détecté. Ajout du module php-mysql.${RESET}"
|
|
||||||
PHP_MODULES+=(php${PHP_VERSION}-mysql)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Vérification PostgreSQL
|
apt install -y "${PHP_MODULES[@]}"
|
||||||
if dpkg -l | grep -q postgresql; then
|
|
||||||
echo -e "${GREEN}PostgreSQL détecté. Ajout du module php-pgsql.${RESET}"
|
|
||||||
PHP_MODULES+=(php${PHP_VERSION}-pgsql)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Installation des modules PHP
|
# 1. Optimisation des fichiers php.ini (CLI, FPM, Apache)
|
||||||
echo -e "${GREEN}Installation des modules PHP...${RESET}"
|
for INI in "/etc/php/${PHP_VERSION}/fpm/php.ini" "/etc/php/${PHP_VERSION}/cli/php.ini" "/etc/php/${PHP_VERSION}/apache2/php.ini"; do
|
||||||
apt install -y "${PHP_MODULES[@]}" || {
|
if [ -f "$INI" ]; then
|
||||||
echo -e "${RED}❌ Échec de l'installation de PHP ou des modules.${RESET}"
|
sed -i 's/memory_limit = .*/memory_limit = 512M/' "$INI"
|
||||||
exit 1
|
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 100M/' "$INI"
|
||||||
}
|
sed -i 's/post_max_size = .*/post_max_size = 100M/' "$INI"
|
||||||
|
sed -i 's/max_execution_time = .*/max_execution_time = 300/' "$INI"
|
||||||
|
sed -i "s|^;*date.timezone =.*|date.timezone = ${TIMEZONE}|" "$INI"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Vérification si Apache est installé et installation du module PHP si nécessaire
|
# 2. Optimisation OPcache (incluant le JIT pour PHP 8.3)
|
||||||
if systemctl list-units --type=service --all | grep -q "apache2.service"; then
|
OPCACHE_INI="/etc/php/${PHP_VERSION}/fpm/conf.d/10-opcache.ini"
|
||||||
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"
|
|
||||||
PHP_INI_DIR="/etc/php/${PHP_VERSION}/fpm/conf.d"
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
# Configuration OPCache
|
|
||||||
OPCACHE_INI="${PHP_INI_DIR}/10-opcache.ini"
|
|
||||||
cat > "$OPCACHE_INI" <<EOF
|
cat > "$OPCACHE_INI" <<EOF
|
||||||
; Configuration OPcache optimisée
|
|
||||||
opcache.enable=1
|
opcache.enable=1
|
||||||
opcache.memory_consumption=128
|
opcache.enable_cli=1
|
||||||
|
opcache.memory_consumption=256
|
||||||
opcache.interned_strings_buffer=16
|
opcache.interned_strings_buffer=16
|
||||||
opcache.max_accelerated_files=10000
|
opcache.max_accelerated_files=20000
|
||||||
opcache.revalidate_freq=60
|
opcache.revalidate_freq=60
|
||||||
opcache.fast_shutdown=1
|
opcache.fast_shutdown=1
|
||||||
opcache.enable_cli=1
|
; Optimisation JIT pour PHP 8.3
|
||||||
|
opcache.jit=tracing
|
||||||
|
opcache.jit_buffer_size=100M
|
||||||
EOF
|
EOF
|
||||||
echo "==> Fichier $OPCACHE_INI mis à jour."
|
|
||||||
|
|
||||||
# Configuration APCu
|
# 3. Optimisation APCu
|
||||||
APCU_INI="${PHP_INI_DIR}/20-apcu.ini"
|
APCU_INI="/etc/php/${PHP_VERSION}/fpm/conf.d/20-apcu.ini"
|
||||||
cat > "$APCU_INI" <<EOF
|
cat > "$APCU_INI" <<EOF
|
||||||
; Configuration APCu optimisée
|
|
||||||
apc.enabled=1
|
apc.enabled=1
|
||||||
apc.shm_size=64M
|
apc.shm_size=64M
|
||||||
apc.ttl=7200
|
apc.ttl=7200
|
||||||
apc.enable_cli=0
|
apc.enable_cli=0
|
||||||
EOF
|
EOF
|
||||||
echo "==> Fichier $APCU_INI mis à jour."
|
|
||||||
|
|
||||||
# Définir la timezone PHP pour CLI et Apache
|
# 4. Optimisation du Pool PHP-FPM (www.conf)
|
||||||
sed -i "s|^;*date.timezone =.*|date.timezone = ${TIMEZONE}|" "${PHP_INI_CLI}"
|
FPM_POOL="/etc/php/${PHP_VERSION}/fpm/pool.d/www.conf"
|
||||||
sed -i "s|^;*date.timezone =.*|date.timezone = ${TIMEZONE}|" "${PHP_INI_APACHE}"
|
if [ -f "$FPM_POOL" ]; then
|
||||||
|
echo -e "${YELLOW}Optimisation des processus FPM...${RESET}"
|
||||||
# Test de la configuration Apache
|
sed -i 's/^pm = .*/pm = dynamic/' "$FPM_POOL"
|
||||||
if systemctl is-active --quiet apache2; then
|
sed -i 's/^pm.max_children = .*/pm.max_children = 80/' "$FPM_POOL"
|
||||||
read -rp "Voulez-vous tester le support de PHP par Apache ? (o/n) : " test_php
|
sed -i 's/^pm.start_servers = .*/pm.start_servers = 10/' "$FPM_POOL"
|
||||||
if [[ "$test_php" =~ ^[oOyY]$ ]]; then
|
sed -i 's/^pm.min_spare_servers = .*/pm.min_spare_servers = 5/' "$FPM_POOL"
|
||||||
echo -e "${YELLOW}Vérification du support de PHP par Apache...${RESET}"
|
sed -i 's/^pm.max_spare_servers = .*/pm.max_spare_servers = 20/' "$FPM_POOL"
|
||||||
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
|
sed -i 's/^;pm.max_requests = .*/pm.max_requests = 1000/' "$FPM_POOL"
|
||||||
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://<IP_SERVEUR>/info.php${RESET}"
|
|
||||||
else
|
|
||||||
echo -e "${YELLOW}Test PHP annulé.${RESET}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -e "${RED}Le service Apache n'est pas actif.${RESET}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}Installation terminée avec succès ! 🚀${RESET}"
|
# Finalisation
|
||||||
|
systemctl restart php${PHP_VERSION}-fpm
|
||||||
|
if systemctl list-units --type=service --all | grep -q "apache2.service"; then
|
||||||
|
apt install -y libapache2-mod-php${PHP_VERSION}
|
||||||
|
systemctl restart apache2
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}Installation et optimisations PHP $PHP_VERSION terminées ! 🚀${RESET}"
|
||||||
Reference in New Issue
Block a user