Il s'agît d'un script permettant l'installation automatique de GLPI dans sa dernière version :
avec :
Le script fonctionnera aussi bien sur Windows Server 2022 Desktop Environnement ou Windows Server 2022 Core que Windows Server 2025 (Desktop/Core)
Pour le déployer, c'est simple, on le copie/colle dans le Terminal ouvert en mode Administrateur, puis on tape "INSTALLER.GLPI".
Il suffira de répondre aux questions pour créer la base SQL de GLPI et c'est tout.
Il s'agît d'une installation sécurisée, avec dossier root dans glpi/public et déport des dossiers glpi/config, glpi/files et glpi/log
On peut aussi procéder étape après étape pour vérifier les URL (ça change parfois).
L'initialisation de GLPI se fait avec la base MariaDB en CLI automatiquement.
Voici le script :
function fINSTALLER.GLPI {
Clear-Host
Write-Host "|---------------------------------------|"
Write-Host " INSTALLATION DE GLPI SECURISEE"
Write-Host "|---------------------------------------|"
Write-Host
####################################
# Install IIS
# Liste des fonctionnalités à installer
Install-WindowsFeature -Name Web-Server
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Mgmt-Tools
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Default-Doc
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Dir-Browsing
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Http-Errors
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Static-Content
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Http-Logging
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Stat-Compression
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-Request-Monitor
Start-Sleep -Seconds 5
Install-WindowsFeature -Name Web-CGI
Start-Sleep -Seconds 5
Restart-Service w3svc -ErrorAction SilentlyContinue
Start-Sleep -Seconds 30
# Pratiquer un second tour, il y a souvent des ratés au premier
Install-WindowsFeature -Name Web-Server
Install-WindowsFeature -Name Web-Mgmt-Tools
Install-WindowsFeature -Name Web-Default-Doc
Install-WindowsFeature -Name Web-Dir-Browsing
Install-WindowsFeature -Name Web-Http-Errors
Install-WindowsFeature -Name Web-Static-Content
Install-WindowsFeature -Name Web-Http-Logging
Install-WindowsFeature -Name Web-Stat-Compression
Install-WindowsFeature -Name Web-Request-Monitor
Install-WindowsFeature -Name Web-CGI
Restart-Service w3svc -ErrorAction SilentlyContinue
Start-Sleep -Seconds 10
####################################
# INSTALLATION DE MariaDB 11.6.2
# vérifier si le dossier C:\Temp existe, sinon le Créer
if (-not (Test-Path "C:\Temp")) {
New-Item -Path "C:\Temp" -ItemType Directory
}
# définir l'URL et le chemin de destination pour le téléchargement
$mariadbUrl = "https://mirrors.ircam.fr/pub/mariadb/mariadb-11.6.2/winx64-packages/mariadb-11.6.2-winx64.msi"
$destinationPath = "C:\Temp\mariadb-11.6.2-winx64.msi"
# télécharger MariaDB
Invoke-WebRequest -Uri $mariadbUrl -OutFile $destinationPath
# Installer MariaDB, configurer le service mariadb et le démarrer
msiexec /i "C:\Temp\mariadb-11.6.2-winx64.msi" /qn
Start-sleep -seconds 30
Set-Location "C:\Program Files\MariaDB 11.6\bin"
.\mysqld.exe --install
Start-sleep -Seconds 10
# L'installation est répétée une seconde fois car plusieurs erreurs étranges sont parfois survenues.
# Ne tenez pas compte de l'erreur 'FATAL ERREUR' si elle s'affiche.
.\mysqld.exe --install
Start-Service -Name 'MySQL'
Start-Sleep -Seconds 5
# Ajouter de manière permanente le chemin au Path
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value "$($env:Path);C:\Program Files\MariaDB 11.6\bin"
# Recharger les variables d'environnement :
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host " "
####################################
# CREATION DE LA BASE SQL POUR GLPI
# Mot de passe root et base SQL pour GLPI
$rootPassword = Read-Host "ENTRER LE MOT DE PASSE ROOT POUR MARIADB"
$dbName = Read-Host "ENTRER LE NOM POUR LA BASE GLPI"
$dbUser = Read-Host "ENTRER UN NOM POUR L'UTILISATEUR ADMINISTRATEUR DE LA BASE GLPI"
$dbPassword = Read-Host "ENTRER UN MOT DE PASSE POUR L'UTILISATEUR ADMINISTRATEUR"
# (11) - créer la base et l'utilisateur privilégié
Set-Location "C:\Program Files\MariaDB 11.6\bin"
.\mysqladmin.exe -uroot create "$dbName"
.\mariadb.exe -uroot -e"CREATE USER '${dbUser}'@'localhost' IDENTIFIED BY '${dbPassword}'"
.\mariadb.exe -uroot -e"GRANT ALL ON ${dbName}.* TO '${dbUser}'@'localhost'"
######################################################
# INSTALLER PHP 8.3.14 ET VC (vs16)
# définir l'URL et le chemin de destination pour le téléchargement
$VCUrl = "https://aka.ms/vs/16/release/VC_redist.x64.exe"
$destinationPath = "C:\Temp\VC_redist.x64.exe"
# télécharger VC
Invoke-WebRequest -Uri $VCUrl -OutFile $destinationPath
# Installer VC
Start-Process -Wait -FilePath "$destinationPath" -ArgumentList "/S" -PassThru
# télécharger et Installer PHP 8.3.14 vs16
$PHPUrl="https://windows.php.net/downloads/releases/php-8.3.14-nts-Win32-vs16-x64.zip"
$destinationPath = "C:\Temp\php-8.3.14-nts-Win32-vs16-x64.zip"
Invoke-WebRequest -Uri $PHPUrl -OutFile $destinationPath
New-Item -Path "C:\PHP" -ItemType directory
Expand-Archive -LiteralPath $destinationPath -DestinationPath "C:\PHP"
# Ajouter de manière permanente le chemin au Path
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value "$($env:Path);C:\PHP"
# Recharger les variables d'environnement :
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# CHARGER LES EXTENSIONS PHP NECESSAIRES :
# Le contenu du fichier php.ini
$content = @'
[PHP]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
zend.exception_ignore_args = On
zend.exception_string_param_max_len = 0
expose_php = On
max_execution_time = 300
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
extension_dir = "C:\PHP\ext"
enable_dl = Off
cgi.force_redirect = 0
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
;;;; ----- EXTENSIONS NECESSAIRES A GLPI ----- ;;;;
extension=zip
extension=bz2
extension=curl
extension=fileinfo
extension=gd
extension=intl
extension=ldap
extension=mbstring
extension=exif
extension=mysqli
extension=openssl
extension=sodium
zend_extension=opcache
error_log = "C:\Windows\Temp\FastCGI - PHP_errors.log"
upload_tmp_dir = "C:\Windows\Temp\"
cgi.fix_pathinfo = 1
fastcgi.impersonate = 1
;;;; ----------------------------------------- ;;;;
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Europe/Paris
[Pdo_mysql]
pdo_mysql.default_socket=
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
;session.cookie_secure = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly = 1
session.cookie_samesite =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = -1
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[ldap]
ldap.max_links = -1
'@
# créer ou remplacer le fichier C:\PHP\php.ini avec le contenu spécifié
Set-Content -Path "C:\PHP\php.ini" -Value $content
######################################################
# TELECHARGER 7z 2409
# télécharge l'installateur de 7-Zip
Invoke-WebRequest -Uri "https://www.7-zip.org/a/7z2409-x64.exe" -OutFile "C:\Temp\7z2409-x64.exe"
# Installe 7-Zip
Start-Process -FilePath "C:\Temp\7z2409-x64.exe" -Args "/S" -Wait
# Recharger les variables d'environnement :
$7zPath = "C:\Program Files\7-Zip"
$env:Path += ";$7zPath"
# Ajouter de manière permanente le chemin au Path
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value "$($env:Path);C:\Program Files\7-Zip"
# Recharger les variables d'environnement :
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
######################################################
# SAUVEGARDER LE CONTENU DE C:\inetpub\wwwroot
# Spécifiez le répertoire source et le fichier ZIP de destination pour la sauvegarde
$sourceDir = "C:\inetpub\wwwroot"
$backupZip = "C:\inetpub\wwwroot_backup.zip"
# Crée une archive ZIP de wwwroot
Compress-Archive -Path $sourceDir -DestinationPath $backupZip
######################################################
# DESACTIVER PUIS SUPPRIMER LE SITE PAR DEFAUT :
# Importe le module WebAdministration pour gérer IIS
Import-Module WebAdministration
# Arrêter le site web par défaut (généralement appelé "Default Web Site")
Write-Host "Arret du site web par defaut..."
Stop-Website -Name "Default Web Site"
# Supprimer le site web par défaut
Write-Host "Suppression du site web par défaut..."
Remove-WebSite -Name "Default Web Site"
# Supprime tous les fichiers et sous-dossiers dans C:\inetpub\wwwroot
Remove-Item -Path "C:\inetpub\wwwroot\iisstart.htm" -Force
Remove-Item -Path "C:\inetpub\wwwroot\iisstart.png" -Force
######################################################
# TELECHARGER GLPI 10.0.17 ET L'INSTALLER DANS C:\inetpub\wwwroot
# URL de téléchargement
$url = "https://github.com/glpi-project/glpi/releases/download/10.0.17/glpi-10.0.17.tgz"
# Chemin temporaire où le fichier sera téléchargé
$tempPath = "C:\Temp\glpi-10.0.17.tgz"
# Chemin vers le répertoire wwwroot
$wwwroot = "C:\inetpub\wwwroot"
# télécharger le fichier
Invoke-WebRequest -Uri $url -OutFile $tempPath
# Décompresser le fichier gzip pour obtenir un fichier tar
Set-Location "$wwwroot"
tar -xvzf "C:\Temp\glpi-10.0.17.tgz"
Start-Sleep -Seconds 5
Write-Host "GLPI a été installé dans $wwwroot."
######################################################
# CREER LE NOUVEAU SITE POUR GLPI :
# Nom du nouveau site web
$websiteName = "GLPI"
# Chemin du dossier racine de GLPI
$websitePath = "C:\inetpub\wwwroot\glpi\public"
# Port sur lequel le site sera accessible
$websitePort = 80
# Supprimer le site si il existe déjà
if (Test-Path "IIS:\Sites\$websiteName") {
Write-Host "Suppression du site existant..."
Remove-WebSite -Name $websiteName
}
# créer le nouveau site web
Write-Host "création du nouveau site web..."
New-Website -Name $websiteName -Port $websitePort -PhysicalPath $websitePath
# démarrer le site web
Write-Host "démarrage du site web..."
Start-Website -Name $websiteName
# Afficher les informations du nouveau site web
Write-Host "Informations du nouveau site web :"
Get-Website | Where-Object { $_.Name -eq $websiteName } | Select-Object Name, ID, State
######################################################
# METTRE EN PLACE LE MAPPAGE DE MODULES PHP
# Unlocker afin de pouvoir ajouter le module de mappage
& $env:windir\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/handlers
Start-sleep -seconds 5
$php = 'C:\PHP\php-cgi.exe'
$configPath = get-webconfiguration 'system.webServer/fastcgi/application' | where-object { $_.fullPath -eq $php }
if (!$configPath) {
add-webconfiguration 'system.webserver/fastcgi' -value @{'fullPath' = $php }
}
$handlerName = "PHP 8.3.14"
$handler = get-webconfiguration 'system.webserver/handlers/add' | where-object { $_.Name -eq $handlerName }
if (!$handler) {
add-webconfiguration 'system.webServer/handlers' -Value @{
Name = $handlerName;
Path = "*.php";
Verb = "*";
Modules = "FastCgiModule";
scriptProcessor=$php;
resourceType='Either'
}
}
# Configurer les paramètres de FastCGI
$configPath = "system.webServer/fastCgi/application[@fullPath='$php']/environmentVariables/environmentVariable"
$config = Get-WebConfiguration $configPath
if (!$config) {
$configPath = "system.webServer/fastCgi/application[@fullPath='$php']/environmentVariables"
Add-WebConfiguration $configPath -Value @{ 'Name' = 'PHP_FCGI_MAX_REQUESTS'; Value = 10050 }
}
# Configure the settings
# Available settings:
# instanceMaxRequests, monitorChangesTo, stderrMode, signalBeforeTerminateSeconds
# activityTimeout, requestTimeout, queueLength, rapidFailsPerMinute,
# flushNamedPipe, protocol
$configPath = "system.webServer/fastCgi/application[@fullPath='$php']"
Set-WebConfigurationProperty $configPath -Name instanceMaxRequests -Value 10000
Set-WebConfigurationProperty $configPath -Name monitorChangesTo -Value 'C:\PHP\php.ini'
######################################################
# CREER UN DOCUMENT PAR DEFAUT POUR index.php
# Ajoute "index.php" comme document par défaut
Add-WebConfiguration -Filter "/system.webServer/defaultDocument/files" -PSPath "IIS:\Sites\$websiteName" -Value @{value='index.php'} -AtIndex 0
Write-Host "Document par défaut ajouté."
######################################################
# OCTROI DES DROITS D'ACCES
$folders = @(
"C:\inetpub\wwwroot\glpi\config",
"C:\inetpub\wwwroot\glpi\files",
"C:\inetpub\wwwroot\glpi\marketplace"
)
$users = @("IIS_IUSRS", "Utilisateurs")
foreach ($folder in $folders) {
foreach ($user in $users) {
Start-Process cmd.exe -ArgumentList "/c icacls `"$folder`" /grant `"$($user):(OI)(CI)M`"" -NoNewWindow -Wait
}
}
######################################################
# RECHARGER IIS ET LA NOUVELLE CONFIG
invoke-command -scriptblock {iisreset /restart }
Start-Sleep -Seconds 5
######################################################
# SECURISER L'INSTALLATION
# Envoyer le contenu du dossier config dans "C:\GLPI_CONFIG\"
New-Item -Path "C:\GLPI_CONFIG" -ItemType directory
Move-Item "C:\inetpub\wwwroot\glpi\config\*" "C:\GLPI_CONFIG\"
# Envoyer le contenu du dossier files dans "C:\
New-Item -Path "C:\GLPI_FILES" -ItemType directory
Move-Item "C:\inetpub\wwwroot\glpi\files\*" "C:\GLPI_FILES\"
# Créer le dossier log dans "C:\
New-Item -Path "C:\GLPI_LOG" -ItemType directory
# Indiquer local_define.php dans downstream.php
$content = @'
<?php
define('GLPI_CONFIG_DIR', 'C:\GLPI_CONFIG');
if (file_exists(GLPI_CONFIG_DIR . '/local_define.php')) {
require_once GLPI_CONFIG_DIR . '/local_define.php';
}
'@
Set-Content -Path "C:\inetpub\wwwroot\glpi\inc\downstream.php" -Value $content
# Redéfinir les chemins des répertoires critiques via des constantes PHP
$content = @'
<?php
define('GLPI_VAR_DIR', 'C:\GLPI_FILES');
define('GLPI_LOG_DIR', 'C:\GLPI_LOG');
'@
Set-Content -Path "C:\GLPI_CONFIG\local_define.php" -Value $content
# Faire une copie de sauvegarde du fichier public\web.config
Rename-Item "C:\inetpub\wwwroot\glpi\public\web.config" "C:\inetpub\wwwroot\glpi\public\web.config.BAK"
# Réécrire le fichier public\web.config pour le module rewrite de IIS
$content = @'
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite GLPI" stopProcessing="true">
<match url=".*" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<!-- NE REECRIT PAS SI UN FICHIER OU UN DOSSIER PHYSIQUE EXISTE -->
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
'@
Set-Content -Path "C:\inetpub\wwwroot\glpi\public\web.config" -Value $content
# Redéfinir le dossier racine du site (DEJA FAIT PLUS HAUT)
# Import-Module WebAdministration
# Start-Sleep -Seconds 2
# Set-ItemProperty "IIS:\Sites\$websiteName" -Name physicalPath -Value "C:\inetpub\wwwroot\glpi\public"
# A ce moment, le site est toujours accessible mais le dossier racine ne permet pas de rediriger les requêtes.
# Cela nécessite l'emploi du module rewrite.
# Si le module rewrite n'est pas installé, cela donne une erreur 500.19 !
Invoke-WebRequest -Uri https://download.microsoft.com/download/1/2/8/128E2E22-C1B9-44A4-BE2A-5859ED1D4592/rewrite_amd64_fr-FR.msi -Outfile "C:\Temp\rewrite_amd64_fr-FR.msi"
msiexec /i "C:\Temp\rewrite_amd64_fr-FR.msi" /qn
######################################################
# INITIALISER GLPI AVEC LA BASE SQL DE MARIADB
# A cause de l'ordre dans lequel l'installation sécurisée s'est faîte, il n'est pas possible de faire l'initialisation via le wizard sur http://localhost ou http://IP-SERVEUR
# Elle doit se faire en CLI exclusivement :
Set-Location "C:\inetpub\wwwroot\glpi"
php .\bin\console db:install --db-host=localhost --db-name="$dbName" --db-user="$dbUser" --db-password="$dbPassword" --no-telemetry --force --no-interaction
# Supprimer le fichier install/install/php après l'initialisation par sécurité
Remove-Item -Path "C:\inetpub\wwwroot\glpi\install\install.php"
# Redémarrer IIS
invoke-command -scriptblock {iisreset /restart }
Write-Host
Write-Host "L'INSTALLATION EST TERMINEE."
Write-Host "CONNECTEZ-VOUS A http://IP-SERVEUR POUR ACCEDER A GLPI"
Write-Host
}
New-Alias -Name INSTALLER.GLPI -Value fINSTALLER.GLPI