Mediawiki install

From wikinotes

Documentation

official install guide https://www.mediawiki.org/wiki/Manual:Installation_guide

FreeBSD

Instructions updated for FreeBSD-12.1

Install Requirements

pkg install \
  mysql80-server \
  mediawiki134-php74 \
  nginx \
  ImageMagick7 \
  py37-pygments \
  php74 \
  php74-intl

Configure nginx

/usr/local/etc/nginx/nginx.conf


# /usr/local/etc/nginx/nginx.conf

user www;
worker_processes auto;
worker_cpu_affinity auto;

events {
  multi_accept on;
  worker_connections 1024;
}

http {
  server {
    listen 80;
    server_name mynotes;
    root /usr/local/www/mediawiki;
    index index.php;
    charset utf-8;
    client_max_body_size 100m;
    client_body_timeout 60;
    include mediawiki.nginx.conf;
  }
}

/usr/local/etc/nginx/mediawiki.nginx.conf


# /usr/local/etc/nginx/mediawiki.nginx.conf

location / {
   index index.php;
   try_files $uri $uri/ @mediawiki;
}
location @mediawiki {
   rewrite ^/(.*)$ /index.php;
}
location ~ \.php5?$ {
   include /usr/local/etc/nginx/fastcgi_params;
   fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
   fastcgi_index index.php5;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   try_files $uri @mediawiki;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
   try_files $uri /index.php;
   expires max;
   log_not_found off;
}
# Restrictions based on the .htaccess files
location ~ ^/(cache|includes|maintenance|languages|serialized|tests|images/deleted)/ {
   deny all;
}
location ~ ^/(bin|docs|extensions|includes|maintenance|mw-config|resources|serialized|tests)/ {
   internal;
}
location ^~ /images/ {
   try_files $uri /index.php;
}
location ~ /\. {
   access_log off;
   log_not_found off;
   deny all;
}
# Enable nginx
echo "nginx_enabled=\"YES\"" >> /etc/rc.conf
service nginx start

Configure php

enable php extensions

Confirm that you have entries within /usr/local/etc/php/*.conf for:

  • php-mysql or php-mysqli
  • php-iconv
  • php-intl

configure php-fpm to listen on socket


For additional security and speed, we'll configure php-fpm to listen on a socket instead of localhost.
On FreeBSD, /usr/local/etc/php-fpm.conf is configured to read files from /usr/local/etc/php-fpm.d/*.conf.
The listen address is configured in /usr/local/etc/php-fpm.d/www.conf.

# /usr/local/etc/php-fpm.d/www.conf

listen = /var/run/php-fpm/php-fpm.sock;

Make sure to create the directory, and if the socket file exists already, it must be readable/writable by the nginx user.

test -d /var/run/php-fpm || mkdir /var/run/php-fpm
chown www:www /var/run/php-fpm

test -f /var/run/php-fpm/php-fpm.sock && chown www:www /var/run/php-fpm/php-fpm.sock


# Enable php fpm
echo "php_fpm_enable=\"YES\"" >> /etc/rc.conf
service php_fpm start

Configure mysql

Setup Database

Create the "wikidb" database, a user for mediawiki, and a user for backups.

MW_PASSWORD="password"
MW_BACKUP_PASSWORD="password"

echo "CREATE DATABASE IF NOT EXISTS wikidb CHARACTER SET utf8 COLLATE utf8_general_ci;" | mysql
echo "GRANT ALL ON wikidb.* TO wiki@localhost IDENTIFIED BY '$MW_PASSWORD'; FLUSH PRIVILEGES;" | mysql
echo "GRANT SELECT, LOCK TABLES, SHOW VIEW   ON *.*   TO   'backup'@'%' IDENTIFIED BY '$MW_BACKUP_PASSWORD'; FLUSH PRIVILEGES;" | mysql

Optionally, you can dump/restore an existing database setup.

# dump 
# (NOTE: only dump wikidb, otherwise you may have issues between mariadb/mysql)
mysqldump wikidb > wikidb.sql

# restore from dump
cat wikidb.sql | mysql

Set Root Password (if necessary)

If you make a mistake, and need to delete your database (/var/db/mysql*),
or your OS is more secure, and requires that you set your own mysql password, you may execute the following.

More up to date instructions may be available here: mysql configuration.

echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';" > /root/resetpass.sql
/usr/local/libexec/mysqld --init-file=resetpass.sql &
pkill mysql


# Enable php fpm
echo "mysql_enable=\"YES\"" >> /etc/rc.conf
service mysql start

Restore Images (if restoring wiki)

If you're restoring a wiki, you'll want to copy your images/ dir into your mediawiki install.
Make sure files are owned by user running nginx.

Complete Setup (if new wiki)

Visit your website from a web browser and complete the setup interactively.

Add Extensions

You may want to add some additional extensions. Mediawiki ships with several options, and there are others available as well.

See mediawiki extensions.

Archlinux

Practically identical to FreeBSD setup.

Podman

This looks interesting wikifundi
But maybe let's start with the official dockerhub image which is likely more familiar, and better supported.

TODO:

WIP

sudo podman pull docker.io/mediawiki:1.40
open 'http://localhost:8080/'