ElementaryOS 0.4: Install MediaWiki for wiki software

This article will describe installing MediaWiki.

1 Install MediaWiki

  • Changing open port of firewall from https to http, you can connect via http.
  • MEDIAWIKI_PASSWD is password of admin user.
#!/bin/sh

set -e

MEDIAWIKI=http://archive.ubuntu.com/ubuntu/pool/universe/m/mediawiki
VERSION=1.27.3
RELEASE=1
MYSQL_VERSION=5.7
[ -z "${MYSQL_PASSWD}" ] && \
  MYSQL_PASSWD=mysql
[ -z "${MEDIAWIKI_PASSWD}" ] && \
  MEDIAWIKI_PASSWD=mediawiki_passwd

mysql_install()
{
  cat <<EOF | sudo debconf-set-selections
mysql-server-${MYSQL_VERSION} mysql-server/root_password password ${MYSQL_PASSWD}
mysql-server-${MYSQL_VERSION} mysql-server/root_password_again password ${MYSQL_PASSWD}
EOF
  sudo apt install -y mysql-server
}

mediawiki_install()
{
  sudo apt install -y devscripts

  mkdir mediawiki
  cd mediawiki/
  wget -q ${MEDIAWIKI}/mediawiki_${VERSION}-${RELEASE}.debian.tar.xz
  wget -q ${MEDIAWIKI}/mediawiki_${VERSION}-${RELEASE}.dsc
  wget -q ${MEDIAWIKI}/mediawiki_${VERSION}-${RELEASE}_all.deb
  wget -q ${MEDIAWIKI}/mediawiki_${VERSION}.orig.tar.gz
  tar zxf mediawiki_${VERSION}.orig.tar.gz
  cd mediawiki-${VERSION}/
  tar xf ../mediawiki_${VERSION}-${RELEASE}.debian.tar.xz

  # shellcheck disable=SC2046
  sudo apt install -y \
       $(dpkg-checkbuilddeps 2>&1 | \
           sed -e 's/.*build dependencies://g' -e 's/([^)]*)//g')
  sed -e 's/php5enmod/phpenmod/g' -i debian/mediawiki.postinst
  sed -e 's/php5dismod/phpdismod/g' -i debian/mediawiki.prerm
  sed -e 's:etc/php5:etc/php/7.0:g' -i debian/mediawiki.install
  sed -e 's/mod_php5/mod_php7.0/g' -i debian/etc/mediawiki.conf

  dpkg-buildpackage -us -uc
  sudo dpkg -i ../*.deb || (sudo apt install -f -y && sudo dpkg -i ../*.deb)

  # Create DB table and LocalSettings.php.
  cd /usr/share/mediawiki
  sudo php maintenance/install.php mediawiki admin \
       --pass "${MEDIAWIKI_PASSWD}" --scriptpath /mediawiki \
       --dbuser root --dbpass "${MYSQL_PASSWD}"
}

apache_install()
{
  sudo apt install -y \
       libapache2-mod-php7.0 php7.0-xml php7.0-intl imagemagick git

  sudo cp /etc/apache2/conf-available/mediawiki.conf \
       /etc/apache2/conf-available/mediawiki.conf.orig

  cat <<EOF | sudo tee /etc/apache2/conf-available/mediawiki.conf
<VirtualHost _default_:443>
  SSLEngine on
  SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
  SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

$(sed -e 's/^/  /g' /etc/apache2/conf-available/mediawiki.conf.orig)
</VirtualHost>
EOF
  sudo a2enmod php7.0
  sudo a2enmod ssl
  sudo systemctl restart apache2
}

mediawiki_main()
{
  mysql_install
  mediawiki_install
  apache_install
}

mediawiki_main

2 Access to MediaWiki

Access to the following URL. Accept this page's certification to browser.

https://<server>/mediawiki

MediaWiki is displayed. Click "Log in" at the top right, and input admin to user and MEDIAWIKI_PASSWD value to password. Then you can login to MediaWiki.

0001_MediaWiki.png