Installation

De Wiki de Jordan LE NUFF
Sauter à la navigation Sauter à la recherche
Ligne 360 : Ligne 360 :
  
 
===Installation de l'extension PluggableAuth===
 
===Installation de l'extension PluggableAuth===
 +
Téléchargement de l'extension :
 +
wget https://extdist.wmflabs.org/dist/extensions/PluggableAuth-REL1_35-d036ae0.tar.gz
 +
 +
Déploiement de l'extension dans le dossier des extensions du mediawiki :
 +
tar -xzf PluggableAuth-REL1_35-d036ae0.tar.gz -C ${WIKI_HOME}/extensions
 +
 +
Ajout de l'extension dans la configuration du mediawiki :
 +
sed -i $(sed -n '/wfLoadExtension/=' ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php|tail -1)"awfLoadExtension( 'PluggableAuth' );" ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php
 +
 +
===Installation de l'extension LDAPAuthorization===

Version du 8 juin 2021 à 08:52

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=${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"
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 ${WIKI_HOME}
	Alias /wikiIsFun ${WIKI_HOME}/index.php
	<Directory "${WIKI_HOME}">
		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 ${WIKI_INSTALL_DIR}/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

Téléchargement de l'extension :

wget https://extdist.wmflabs.org/dist/extensions/LDAPProvider-REL1_35-27fccf1.tar.gz

Déploiement de l'extension dans le dossier des extensions du mediawiki :

tar -xzf DAPProvider-REL1_35-27fccf1.tar.gz -C ${WIKI_HOME}/extensions

Ajout de l'extension dans la configuration du mediawiki :

sed -i $(sed -n '/wfLoadExtension/=' ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php|tail -1)"awfLoadExtension( 'LDAPProvider' );" ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php

Mise à jour de la base de données pour prise en compte de la nouvelle extension :

php ${WIKI_HOME}/maintenance/update.php

Ajout de la configuration pour la connexion à l'Active Directory de l'entreprise :

sed 's/\\t/\t/g' <<EOF >> ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php

# LDAPProvider extension configuration
\$LDAPProviderDomainConfigProvider = function() {
\t\$config = [
\t\t'LDAP' => [
\t\t\t'connection' => [
\t\t\t\t"server" => "ldap.mydomain.com",
\t\t\t\t"user" => "CN=xxxxxxxxxx,OU=xxxxxxxxxxx,OU=xxxxxxxxxxxxxxxxxx,DC=mydomain,DC=com",
\t\t\t\t"pass" => 'xxxxxxxxxxxxxxxxx',
\t\t\t\t"options" => [
\t\t\t\t\t"LDAP_OPT_DEREF" => 1
\t\t\t\t],
\t\t\t\t"basedn" => "DC=mydomain,DC=com",
\t\t\t\t"groupbasedn" => "DC=mydomain,DC=com",
\t\t\t\t"userbasedn" => "DC=mydomain,DC=com",
\t\t\t\t"searchattribute" => "sAMAccountName",
\t\t\t\t"searchstring" => "USER-NAME@bm-energies.com",
\t\t\t\t"usernameattribute" => "samaccountname",
\t\t\t\t"realnameattribute" => "displayName",
\t\t\t\t"emailattribute" => "mail"
\t\t\t]
\t\t]
\t];
\t
\treturn new \MediaWiki\Extension\LDAPProvider\DomainConfigProvider\InlinePHPArray( \$config );
};
# End of LDAPProvider extension configuration
EOF

Installation de l'extension PluggableAuth

Téléchargement de l'extension :

wget https://extdist.wmflabs.org/dist/extensions/PluggableAuth-REL1_35-d036ae0.tar.gz

Déploiement de l'extension dans le dossier des extensions du mediawiki :

tar -xzf PluggableAuth-REL1_35-d036ae0.tar.gz -C ${WIKI_HOME}/extensions

Ajout de l'extension dans la configuration du mediawiki :

sed -i $(sed -n '/wfLoadExtension/=' ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php|tail -1)"awfLoadExtension( 'PluggableAuth' );" ${WIKI_INSTALL_DIR}/PARAM/LocalSettings.php

Installation de l'extension LDAPAuthorization