Installation

De Wiki de Jordan LE NUFF
Sauter à la navigation Sauter à la recherche
Ligne 125 : Ligne 125 :
 
wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.zip
 
wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.zip
 
unzip mediawiki-1.35.2.zip
 
unzip mediawiki-1.35.2.zip
mkdir -p /data/www/wikis/wikiIsFun/{DATA/images,LOG,PARAM}
+
mkdir -p ${WIKI_INSTALL_DIR}/{DATA/images,LOG,PARAM}
mv mediawiki-1.35.2 /data/www/wikis/wikiIsFun/
+
mv mediawiki-1.35.2 ${WIKI_INSTALL_DIR}/
cd /data/www/wikis/wikiIsFun
+
cd ${WIKI_INSTALL_DIR}
 
ln -s mediawiki-1.35.2 CURRENT
 
ln -s mediawiki-1.35.2 CURRENT
 
mv CURRENT/images/* DATA/images/
 
mv CURRENT/images/* DATA/images/
Ligne 194 : Ligne 194 :
 
<pre>
 
<pre>
 
cd CURRENT/
 
cd CURRENT/
php maintenance/install.php --confpath=/data/www/wikis/wikiIsFun/PARAM --dbname=wikiIsFun_db --dbpass=xxxxxxxxxxxxxxxxx --lang=fr --server="http://mygreat.domain.com" --scriptpath=/wikiIsFun --with-extensions --pass=funwikiadm --env-checks "Médiawiki Fun" "admwikiisfun"
+
php maintenance/install.php --confpath=/PARAM --dbname=wikiIsFun_db --dbpass=xxxxxxxxxxxxxxxxx --lang=fr --server="http://mygreat.domain.com" --scriptpath=/wikiIsFun --with-extensions --pass=funwikiadm --env-checks "Médiawiki Fun" "admwikiisfun"
 
</pre>
 
</pre>
  
 
{{terminal|text=
 
{{terminal|text=
[root@myserver CURRENT]# php maintenance/install.php --confpath=/data/www/wikis/wikiIsFun/PARAM --dbname=wikiIsFun_db --dbpass=xxxxxxxxxxxxxxxxx --lang=fr --server="http://mygreat.domain.com" --scriptpath=/wikiIsFun --with-extensions --pass=funwikiadm --env-checks "Médiawiki Fun" "admwikiisfun"
+
[root@myserver CURRENT]# php maintenance/install.php --confpath=${WIKI_INSTALL_DIR}/PARAM --dbname=wikiIsFun_db --dbpass=xxxxxxxxxxxxxxxxx --lang=fr --server="http://mygreat.domain.com" --scriptpath=/wikiIsFun --with-extensions --pass=funwikiadm --env-checks "Médiawiki Fun" "admwikiisfun"
 
PHP 7.3.27 est installé.
 
PHP 7.3.27 est installé.
 
La bibliothèque graphique GD intégrée a été trouvée. La miniaturisation d’images sera activée si vous activez le téléversement de fichiers.
 
La bibliothèque graphique GD intégrée a été trouvée. La miniaturisation d’images sera activée si vous activez le téléversement de fichiers.
Ligne 204 : Ligne 204 :
 
Utilisation du nom de serveur « http://localhost ».
 
Utilisation du nom de serveur « http://localhost ».
 
Utilisation de l’URL de serveur « http://mygreat.domain.com/wikiIsFun ».
 
Utilisation de l’URL de serveur « http://mygreat.domain.com/wikiIsFun ».
Attention : votre répertoire par défaut pour les téléversements (/data/www/wikis/wikiIsFun/mediawiki-1.35.2/images/) n’est pas contrôlé concernant la vulnérabilité d’exécution de scripts arbitraires lors de l’installation CLI.
+
Attention : votre répertoire par défaut pour les téléversements (${WIKI_INSTALL_DIR}/mediawiki-1.35.2/images/) n’est pas contrôlé concernant la vulnérabilité d’exécution de scripts arbitraires lors de l’installation CLI.
 
Utilisation de l’extension intl de PHP pour la normalisation Unicode.
 
Utilisation de l’extension intl de PHP pour la normalisation Unicode.
 
L’environnement a été vérifié. Vous pouvez installer MediaWiki.
 
L’environnement a été vérifié. Vous pouvez installer MediaWiki.

Version du 8 juin 2021 à 07:12

Présentation

Cette page a pour objet de décrire comment installer une instance de MediaWiki.

Contexte

Cette procédure sera réalisée avec les éléments techniques suivants :

  • Serveur : serveur CentOs 7
  • Groupe d'utilisateurs : www
  • Serveur web : Apache 2.4
  • Utilisateur : www
  • PHP : version 7.3.27 en mode PHP-FPM
    • Utilisateur : php-fpm
  • MediaWiki : version 1.35.2

Le MedaWiki sera accessible dans un sous-dossier /wikiIsFun dans l'URL.

Prérequis

Pour les prérequis, il suffit de respecter ceux qui sont listés dans la documentation officielle de MediaWiki.

Variables nécessaires à l'installation

Pour faciliter le déploiement, sa portabilité et son éventuellement automatisation, il est nécessaire de définir les variables suivantes :

  • export PHP_VERSION=7.3.27
    Version de PHP à utiliser
  • export WIKI_INSTALL_DIR=/data/www/wikis/wikiIsFun
    Dossier général du mediawiki
  • export WIKI_HOME=${WIKI_INSTALL_DIR}/CURRENT
    Dossier de l'instance principale du mediawiki

Installation PHP

export PHP_VERSION=7.3.27
mkdir -p /local/php/php-${PHP_VERSION}
wget https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz
tar -zxf php-${PHP_VERSION}.tar.gz -C /local/builds
cd /local/builds/php-${PHP_VERSION}
./configure \
--prefix=/local/php/php-${PHP_VERSION} \
--with-config-file-path=/local/php/php-${PHP_VERSION} \
--disable-all \
--enable-cli \
--enable-static \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-ipv6 \
--enable-calendar \
--enable-intl \
--enable-mbstring \
--enable-zip \
--with-mysqli \
--with-curl \
--with-openssl \
--enable-pdo \
--with-pdo-mysql \
--enable-shared=pdo-mysql \
--enable-phar \
--enable-opcache \
--with-libdir=lib64 \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-webp-dir \
--with-bz2 \
--enable-json \
--enable-hash \
--with-pear \
--enable-xml \
--enable-libxml \
--enable-session \
--enable-ctype \
--with-iconv \
--enable-fileinfo \
--enable-dom && make -j && make install
cp /local/php/php-${PHP_VERSION}/etc/php-fpm.conf.default /local/php/php-${PHP_VERSION}/etc/php-fpm.conf
sed -i -e 's@;pid = run/php-fpm.pid@;pid = run/php-fpm.pid\npid = run/php-fpm.pid@g' /local/php/php-${PHP_VERSION}/etc/php-fpm.conf
cp /local/builds/php-${PHP_VERSION}/php.ini-production /local/php/php-${PHP_VERSION}/php.ini
sed -i -e 's@;error_log = syslog@;error_log = syslog\nerror_log = /data/logs/localhost/localhost_php-${PHP_VERSION}.log@g' /local/php/php-${PHP_VERSION}/php.ini
sed -i -e 's@;sendmail_path =@sendmail_path = "/usr/bin/msmtp -t"@g' /local/php/php-${PHP_VERSION}/php.ini
sed -i -e 's@;sendmail_path =@sendmail_path = "/usr/sbin/sendmail -t -i"@g' /local/php/php-${PHP_VERSION}/php.ini
sed -i -e 's@;date.timezone =@date.timezone = "Europe/Paris"@g' /local/php/php-${PHP_VERSION}/php.ini
sed -i -e 's@\[opcache\]@\[opcache\]\nzend_extension='$(grep no-debug-non-zts /local/php/php-${PHP_VERSION}/bin/php-config|awk -F\' '{print $2}')'/opcache.so@g' /local/php/php-${PHP_VERSION}/php.ini
/local/php/php-${PHP_VERSION}/bin/pear config-set php_ini /local/php/php-${PHP_VERSION}/php.ini system
/local/php/php-${PHP_VERSION}/bin/pecl config-set php_ini /local/php/php-${PHP_VERSION}/php.ini system
cat <<EOF >/local/php/php-${PHP_VERSION}/etc/php-fpm.d/localhost.conf
[localhost]
listen = /local/php/sockets/php-${PHP_VERSION}_\$pool.sock
listen.owner = php-fpm
listen.group = www
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /php-fpm-status
ping.path = /php-fpm-ping
access.log = /data/logs/\$pool/\$pool_php-${PHP_VERSION}.access.log
slowlog = /data/logs/\$pool/\$pool_php-${PHP_VERSION}.log.slow
php_admin_value[error_log] = /data/logs/\$pool/\$pool_php-${PHP_VERSION}.log
php_admin_flag[log_errors] = on
php_admin_value[error_reporting] = E_ALL
php_admin_value[session.save_path] = "/local/php/sessions/\$pool/"
php_value[session.save_path] = "/local/php/\$pool/"
EOF
mkdir -p /local/php/sockets
mkdir -p /local/php/sessions
chown -R php-fpm:www /local/php
cp /local/builds/php-${PHP_VERSION}/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
sed -i -e 's/\[Service\]/\[Service\]\nUMask=0007\nUser=php-fpm\nGroup=www\nEnvironment="PHP_VERSION='${PHP_VERSION}'"/g' /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
sed -i -e 's/^ProtectKernelModules/#ProtectKernelModules/g' /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
sed -i -e 's/^ProtectKernelTunables/#ProtectKernelTunables/g' /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
sed -i -e 's/^ProtectControlGroups/#ProtectControlGroups/g' /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
sed -i -e 's/^RestrictRealtime/#RestrictRealtime/g' /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
sed -i -e 's/^RestrictNamespaces/#RestrictNamespaces/g' /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
chmod o+r /usr/lib/systemd/system/php-fpm-${PHP_VERSION}.service
systemctl daemon-reload
systemctl start php-fpm-${PHP_VERSION}.service
systemctl enable php-fpm-${PHP_VERSION}.service
pecl install apcu

Commandes

wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.zip
unzip mediawiki-1.35.2.zip
mkdir -p ${WIKI_INSTALL_DIR}/{DATA/images,LOG,PARAM}
mv mediawiki-1.35.2 ${WIKI_INSTALL_DIR}/
cd ${WIKI_INSTALL_DIR}
ln -s mediawiki-1.35.2 CURRENT
mv CURRENT/images/* DATA/images/
mv CURRENT/images/.htaccess DATA/images/
rmdir CURRENT/images
ln -s ../DATA/images CURRENT/images
chown -R php-fpm:www .
find . -type f -exec chmod 660 {} \;
find . -type d -exec chmod 770 {} \;

Création de la base de données :

CREATE DATABASE wikiIsFun_db;
CREATE USER 'wikiIsFun_user'@'localhost' IDENTIFIED BY 'xxxxxxxxxxxxxxxxxx';
GRANT ALL PRIVILEGES ON wikiIsFun_db.* TO 'wikiIsFun_user'@'localhost' WITH GRANT OPTION;

Dans le cas d'un Wiki utilisant la même base d'utilisateur qu'un autre Wiki, dans MySQL, donner les droits suivants :

GRANT SELECT, UPDATE ON mediawiki_db.user TO 'wikiIsFun_user'@'localhost';
GRANT SELECT, UPDATE ON mediawiki_db.user_properties TO 'wikiIsFun_user'@'localhost';
GRANT SELECT, UPDATE ON mediawiki_db.actor TO 'wikiIsFun_user'@'localhost';
mkdir /data/logs/wikiIsFun /data/sessions/wikiIsFun
chown php-fpm:www /data/logs/wikiIsFun /data/sessions/wikiIsFun
chmod 770 /data/logs/wikiIsFun /data/sessions/wikiIsFun

Contenu de la configuration du socket PHP pour wikiIsFun /local/php/php-${PHP_VERSION}/etc/php-fpm.d/wikiIsFun.conf :

[wikiIsFun]
;Paramètres du socket
listen = ../sockets/php-${PHP_VERSION}-$pool.sock
listen.owner = php-fpm
listen.group = www
listen.mode = 0660

; Définition du chemin d'accès des logs
access.log = /data/logs/$pool/$pool_php-${PHP_VERSION}.access.log
slowlog = /data/logs/$pool/$pool_php-${PHP_VERSION}.slow.log
php_admin_value[error_log] = /data/logs/$pool/$pool_php-${PHP_VERSION}.error.log
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = on
; https://www.php.net/manual/fr/errorfunc.constants.php
php_admin_value[error_reporting] = E_ALL
php_admin_value[session.save_path] = "/data/sessions/$pool/"
php_value[session.save_path] = "/data/sessions/$pool/"

; Tuning du pool php-fpm
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /php-fpm-status
ping.path = /php-fpm-ping
systemctl reload php7-fpm.service
cd CURRENT/
php maintenance/install.php --confpath=/PARAM --dbname=wikiIsFun_db --dbpass=xxxxxxxxxxxxxxxxx --lang=fr --server="http://mygreat.domain.com" --scriptpath=/wikiIsFun --with-extensions --pass=funwikiadm --env-checks "Médiawiki Fun" "admwikiisfun"
Putty icon.png Console SSH
ln -s ../PARAM/LocalSettings.php LocalSettings.php

Configuration

URL courtes et Apache

Ajout à la configuration Apache /local/www/httpd-2.4.39/conf/sites/02_mygreat.domain.com.conf du contenu suivant :

...
	# Configuration WikiIsFun
	Alias /mediawikiIsFun /data/www/wikis/wikiIsFun/CURRENT
	Alias /wikiIsFun /data/www/wikis/wikiIsFun/CURRENT/index.php
	<Directory "/data/www/wikis/wikiIsFun/CURRENT">
		Options FollowSymLinks
		RewriteEngine On
		RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
		DirectoryIndex index.php
		AllowOverride All
		Require all granted
		<FilesMatch \.php$>
			SetHandler "proxy:unix:/local/php/sockets/php-7.3.27-wikiIsFun.sock|fcgi://localhost"
		</FilesMatch>
	</Directory>
	# Fin de configuration WikiIsFun
...
systemctl reload http.service

Dans le fichier /data/www/wikis/wikiIsFun/PARAM/LocalSettings.php, modification de la section suivante :

...
$wgScriptPath = "/wikiIsFun";
...

Par :

...
$wgScriptPath = "/mediawikiIsFun";
$wgScriptExtension = ".php";
$wgArticlePath = "/wikiIsFun/$1";
$wgUsePathInfo = true;
...

Le mediawiki est désormais accessible sur http://mygreat.domain.com/wikiIsFun/

Logs

Dans le fichier ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php, ajout de la section suivante :

...
$wgUsePathInfo = true;

/**
 * The debug log file must never be publicly accessible because it
 * contains private data. But ensure that the directory is writeable by the
 * PHP script running within your Web server.
 * The filename is with the database name of the wiki.
 */
$wgDebugLogFile = "$IP/../LOG/mediawiki_debug.log";

## The protocol and server name to use in fully-qualified URLs
...

Dans le dossier ${WIKI_INSTALL_DIR}/DATA/images, dépôt du logo my_great_company_logo_180x120.png.

Dans le fichier ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php, modification de la section suivante :

...

## The URL paths to the logo.  Make sure you change this from the default,
## or else you'll overwrite your logo when you upgrade!
$wgLogos = [ '1x' => "$wgResourceBasePath/images/my_great_company_logo_180x120.png" ];

...

Ajout de types de fichier particuliers

Afin de pouvoir téléverser des types de fichier non-standard, il faut ajouter le type de fichier attendu dans le tableau PHP $wgFileExtensions. Il faut également désactiver la vérification des types MIME en fonction de l'extension de fichier avec la variable $wgVerifyMimeType.

Ce type d'ajout présentant une faille de sécurité, il convient de n'activer cette configuration que lorsque c'est nécessaire, et de la commenter une fois le téléversement terminé.

Ainsi, dans le fichier ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php, ajout de la section (commentée) suivante :

# Autoriser des extensions de fichiers supplémentaires à l'upload
//$wgFileExtensions[] = 'rpm';

# Désactiver la vérification des types MIME en fonction de l'extension de fichier lors de l'upload
//$wgVerifyMimeType  = false;

Authentification Active Directory

Selon la documentation officielle du MediaWiki sur l'intégration d'une authentification avec un Active Directory, il faut installer les extensions suivantes :

Installation de l'extension LDAPProvider