install_glpi.sh
Note de lecture générée automatiquement
Le vrai fichier est
scripts/web/install_glpi.sh(Obsidian n’affiche pas les scripts eux-mêmes). Ne modifie pas cette note : modifie le script, puis relancepython3 generer_vues_obsidian.pydans le dossierscripts.
- À quoi il sert : GLPI (dernière version) complet
- Lancer (dans le dossier
scripts/web/) :sudo ./install_glpi.sh [version] - Fiche : SV04 - GLPI et gestion de parc (ITIL)
- Retour : 00 - Tous les scripts
Code
#!/usr/bin/env bash
# =============================================================================
# install_glpi.sh — Installe GLPI (dernière version 11.x) sur Debian 13 / Ubuntu 24.04
# Apache + PHP + MariaDB, base "glpi", VirtualHost avec /public comme racine,
# tâche cron, dossiers sécurisés.
#
# Usage : sudo ./install_glpi.sh [version] ex. : sudo ./install_glpi.sh 11.0.5
# Sans argument, le script interroge GitHub pour trouver la dernière version.
# Puis : http://IP_DE_LA_VM/ → assistant d'installation
# Base : localhost / glpi / (mot de passe saisi ci-dessous) / base glpi
# =============================================================================
set -euo pipefail
$EUID -eq 0 || { echo "Lance ce script avec sudo." >&2; exit 1; }
export DEBIAN_FRONTEND=noninteractive
apt-get update -q
apt-get install -y -q apache2 mariadb-server curl jq \
php libapache2-mod-php php-mysql php-curl php-gd php-intl php-mbstring php-xml \
php-zip php-bz2 php-ldap php-bcmath php-opcache
php_version=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')
echo "PHP $php_version détecté (GLPI 11 exige PHP 8.2 ou plus)."
# --- Version de GLPI -------------------------------------------------------------
version="${1:-}"
if -z "$version"; then
version=$(curl -fsSL https://api.github.com/repos/glpi-project/glpi/releases/latest | jq -r .tag_name)
fi
echo "Installation de GLPI $version"
# --- Base de données -------------------------------------------------------------
read -r -s -p "Mot de passe à donner à l'utilisateur MariaDB 'glpi' : " mdp_glpi; echo
mariadb <<SQL
CREATE DATABASE IF NOT EXISTS glpi CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER IF NOT EXISTS 'glpi'@'localhost' IDENTIFIED BY '${mdp_glpi}';
GRANT ALL PRIVILEGES ON glpi.* TO 'glpi'@'localhost';
GRANT SELECT ON mysql.time_zone_name TO 'glpi'@'localhost';
FLUSH PRIVILEGES;
SQL
# Fuseaux horaires (évite un avertissement de l'assistant)
mariadb-tzinfo-to-sql /usr/share/zoneinfo 2>/dev/null | mariadb mysql || true
# --- Fichiers ----------------------------------------------------------------------
cd /tmp
curl -fsSL -o glpi.tgz "https://github.com/glpi-project/glpi/releases/download/${version}/glpi-${version}.tgz"
rm -rf /var/www/glpi
tar -xzf glpi.tgz -C /var/www/
chown -R www-data:www-data /var/www/glpi
find /var/www/glpi -type d -exec chmod 755 {} \;
find /var/www/glpi -type f -exec chmod 644 {} \;
# --- Apache : la racine web est le dossier public/ ---------------------------------
cat > /etc/apache2/sites-available/glpi.conf <<'CONF'
<VirtualHost *:80>
ServerName glpi.local
DocumentRoot /var/www/glpi/public
<Directory /var/www/glpi/public>
Require all granted
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
ErrorLog ${APACHE_LOG_DIR}/glpi_error.log
CustomLog ${APACHE_LOG_DIR}/glpi_access.log combined
</VirtualHost>
CONF
a2enmod rewrite > /dev/null
a2dissite 000-default.conf > /dev/null || true
a2ensite glpi.conf > /dev/null
# Sécurité recommandée par GLPI : cookies de session HttpOnly
fichier_php_ini="/etc/php/${php_version}/apache2/php.ini"
if -f "$fichier_php_ini"; then
sed -i 's/^;\?session.cookie_httponly.*/session.cookie_httponly = On/' "$fichier_php_ini"
fi
systemctl restart apache2
# --- Tâches automatiques -------------------------------------------------------------
echo "* * * * * www-data /usr/bin/php /var/www/glpi/front/cron.php > /dev/null 2>&1" > /etc/cron.d/glpi
ip_vm=$(hostname -I | awk '{print $1}')
echo
echo "✅ GLPI $version copié. Termine l'installation sur : http://$ip_vm/"
echo " Base : serveur 'localhost', utilisateur 'glpi', base 'glpi'."
echo "⚠ Ensuite : changer les mots de passe des comptes glpi, tech, normal, post-only"
echo " et supprimer le fichier d'installation : sudo rm /var/www/glpi/install/install.php"