MediaWiki Install 2022-09-01

From Traxel Wiki
Jump to navigation Jump to search


Notes

Change "traxel" to Your Identifier

I'm using "traxel" here because that's my domain. Anywhere you see "traxel" below you should change that to suit your case. For HeatSync Labs, I'd recommend "hsl" or "heatsynclabs".

Additional Modules

  • Survey Extension, should work well for HeatSync

Create a Host

I'm not going to document this part. Pick your favorite hosting service and create a Debian 10 host.

If your provider supports it, get a permanent IP address and point it at the new host. This will let you blow away the host, create a new one, point the IP at the new host, and redo the install without having to update the DNS entry and wait for the cascade.

If your provider has default-deny firewalling, make sure ports 22, 80, and 443 are open, which will allow SSH, HTTP, and HTTPS, respectively.

Note the IP address.

IP: 35.160.237.84

System Update and Core Software

Following is based, in part, on MediaWiki Installation Requirements.

Log in to your host.

Create the setup script:

$ mkdir bin
$ cat > bin/system-update.sh
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y emacs-nox
sudo apt install -y apache2 certbot python3-certbot-apache
sudo apt install -y mariadb-server php php-mysql libapache2-mod-php
sudo apt install -y php-xml php-mbstring php-apcu php-intl php-cli php-curl
sudo apt install -y git imagemagick texlive

Control-d will exit and save the file.

$ chmod ug+x bin/system-update.sh
$ ./bin/system-update.sh

If you're not sure that it all ran correctly, you can safely re-run the script. You'll know it ran correctly if the output is roughly 40 lines saying things like, "already the newest", "0 upgraded", and "... Done".

MediaWiki Tarball

I am installing from the tarball instead of using the Debian package because other package tools, like RPM or Snap, or other distros than Debian, might put directories in different places. Following the MediaWiki tarball instructions should be close to universal.

$ mkdir apps
$ cd apps
$ wget https://releases.wikimedia.org/mediawiki/1.38/mediawiki-1.38.2.tar.gz

One difference on other distros may be the location of web content directories. Debian puts them in /var/www. Adjust the following commands to match your distro's structure if you're not using Deb 10.

I'm moving the stock Apache site to a directory for static content, and linking mediawiki to the wiki engine directory. The symlink will make it a bit easier to upgrade to the next version of MediaWiki.

$ cd /var/www
$ sudo tar -xvzf ~/apps/mediawiki-1.38.2.tar.gz
$ sudo mv html static
$ sudo ln -s mediawiki-1.38.2 mediawiki

Configure MariaDB

Pick a username for MediaWiki to use (I'm using wiki_wiki as an example).

Pick a database name (I'm using traxel_wiki as an example). We'll also create "install_wiki" to hold the default install as a backup in case we have troubles cloning the legacy database.

Pick a password other than "CHANGE THIS PASSWORD".

$ cd ~/bin
$ sudo cat > mariadb-wiki-account.sql
create database install_wiki;
create database traxel_wiki;
grant all on install_wiki.* to 'wiki_wiki'@'localhost' identified by 'CHANGE THIS PASSWORD';
grant all on traxel_wiki.* to 'wiki_wiki'@'localhost' identified by 'CHANGE THIS PASSWORD';
flush privileges;

Control-D to write the file.

$ sudo mariadb < mariadb-wiki-account.sql

Then you can verify it worked if you like. (there won't be any tables, but it shouldn't give you an auth error)

$ mariadb -u wiki_wiki -p
MariaDB> show tables in traxel_wiki;
MariaDB> exit

Configure Temporary DNS

This is assuming that there is a legacy wiki running on wiki.domain.com, and you will be bringing up the new machine with the temporary name wiki-new.domain.com. Once you have the new machine running and validated, you will migrate wiki.domain.com to the new machine.

Go to your domain name registrar and add an A Record for the machine and two CNAME records; one for the wiki engine and one for static content. I'm using "jimbo2" as the machine name, you can use whatever you like.

Type Host Value TTL
A Record jimbo2 35.160.237.84 Automatic
CNAME wiki-new jimbo2.traxel.com Automatic
CNAME wiki-static-new jimbo2.traxel.com Automatic

It may take a bit to cascade through your resolvers. If you want to be able to hit it immediately, you can update your /etc/hosts file. Add a line like "35.160.237.84 mediawiki.domain.com" but with your IP and domain, after the localhost mappings.

Configure Apache

Next we'll add an Apache config for wiki-new.domain.com that points to the MediaWiki engine, and another for wiki-static-new.domain.com that points to a static content directory.

$ cd ~/
$ mkdir -p conf/apache
$ cd conf/apache

/etc/apache2/sites-available/wiki.conf

$ cd ~/conf/apache
$ cat > wiki.conf
<VirtualHost *:80>
  ServerName wiki.traxel.com
  ServerAlias wiki-new.traxel.com

  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/mediawiki

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/sites-available/wiki-static.conf

$ cd ~/conf/apache
$ cat > wiki-static.conf
<VirtualHost *:80>
  ServerName wiki-static-new.traxel.com

  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/static

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Copy to sites-available

$ sudo cp ~/conf/apache/*conf /etc/apache2/sites-available/

Activate Host Configs

Activate the mediawiki conf and bounce the server.

$ sudo a2ensite wiki wiki-static
$ sudo service apache2 restart

Check Sites

Now you should be able to see the two Apache configs at the desired host addresses:

If you went through this script quickly, the DNS may not have cascaded yet. You could try editing your /etc/hosts file, or go get a cup of coffee and read Reddit for half an hour, then try again.

Enable TLS (SSL)

To keep your errors easy to diagnose and resolve, do one site at a time and verify / fix errors independently.

$ sudo certbot --apache -d wiki-new.traxel.com

When it asks about redirects, choose, "2: Redirect - Make all requests redirect to secure HTTPS access."

Hit http://wiki-new.traxel.com and verify it redirects to https:// and shows the correct content. If there are any errors, fix them before moving on.

$ sudo certbot --apache -d wiki-static-new.traxel.com

When it asks about redirects, choose, "2: Redirect - Make all requests redirect to secure HTTPS access."

Hit http://wiki-static-new.traxel.com and verify it redirects to https:// and shows the correct content. Fix any errors before moving on.

Run The MediaWiki Config Script

Get a logo image file ready to drag and drop. You will need it later.

Go to https://wiki-new.traxel.com/ and click on the setup hyperlink.

Connect to Database

  • database host: localhost
  • database name: install_wiki
  • database table prefix: <LEAVE BLANK>
  • database username: wiki_wiki
  • database password: <YOUR PASSWORD>

Database Settings

I use the same settings for web access as for installation.

Name

  • name of wiki: Traxel Wiki
  • project namespace: same as the wiki name
  • your username: <YourWikiname, conventionally FirstnameLastname>
  • password: <A DIFFERENT PASSWORD>
  • repeat password: <THE SAME, DIFFERENT PASSWORD>
  • email address: <LEAVE BLANK>
  • ask me more questions: tick this radio button
  • I'm bored already: don't tick this, there's important stuff ahead

Options

In the sections below from Special Pages to Other, you can get more info on extensions by tacking the extension name after the colon in the following URL: https://www.mediawiki.org/wiki/Extension:TextExtracts

  • user rights profile: Authorized editors only
  • copyright and license: No license footer
  • email settings: uncheck Enable outbound email
  • skins: select all and use Vector as the default
  • special pages: I include all 5
  • editors: I include all 3
  • parser hooks: I include CategoryTree, Cite, Math, SyntaxHighlight_GeSHi, and TemplateData
  • media handlers: I include PdfHandler
  • spam prevention: I don't use these, since I used "authorized editors" above.
  • api: I include PageImages
  • Other: i include MultimediaViewer and SecureLinkFixer
  • images and file uploads: check "enable file uploads", leave the default directory setting
  • personalization: Drag your wiki logo to both the "Logo" and "Sidebar Logo" settings. (Note: it is a *lot* easier to do this now, don't skip this step)
  • advanced configuration: use PHP caching - we installed apcu earlier.

Language

Pick your language.

Install

When you click continue, this page will write the database.

Complete

This page will automatically start a download of the LocalSettings.php file.

Install LocalSettings.php

Push a copy to the server at ~/conf/LocalSettings-[datestamp].php .

Log in to the server to install the config. While we're at it, we'll set the images directory structure to be owned by www-data, so image uploads will work.

$ sudo cp ~/conf/LocalSettings-traxel-2022-09-05.php /var/www/mediawiki/LocalSettings.php
$ sudo chown -R www-data /var/www/mediawiki/images
$ sudo service apache2 restart

Now the wiki should be live.

https://wiki-new.traxel.com/

Clone the Legacy Wiki

LocalSettings.php

Compare the LocalSettings.php from the legacy server with the new LocalSettings.php file.

I used diff and did a line by line check. It was pretty quick and all the differences were reasonable.

Database

Log in to the legacy server, stop Apache, and dump the database.

$ sudo service apache stop
$ mysqldump -p -u wiki_wiki traxel_wiki | bzip2 > traxel-wiki-dump-2022-09-05.sql.bz2

Transfer the database dump to the new server.

Load the database dump into the new server.

$ bzip2 -dc traxel-wiki-dump-2022-09-05.sql.bz2 | mariadb -p -u wiki_wiki traxel_wiki

Edit /var/www/mediawiki/LocalSettings.php. Change $wgDBname = "install_wiki"; to $wgDBname = "traxel_wiki"; then bounce Apache.

$ sudo emacs -nw /var/www/mediawiki/LocalSettings.php
$ sudo service apache2 restart

Test The Wiki

Check out the wiki, make sure everything is working. The next step is the cutover; if anything isn't working right, it's easy to fix now.

Switch DNS

Go to your DNS provider and point wiki and wiki-new to your new server.

Update Apache Configs

Open

Get New TLS Certificates

Set Up Nightly Backups

This script will make the backup available on the static content site. Until the DNS cutover, you can see it at https://wiki-static-new.traxel.com/backups Later it will be available at https://wiki-static.traxel.com/backups .

This assumes that the administrator user account is "admin".

sudo mkdir /var/www/static/backups
sudo chown admin /var/www/static/backups

/home/admin/bin/nightly_backup.sh

export db_pass=YOUR_PASSWORD
export dstamp=`date +%Y-%m-%d`
export bundle_dir=wiki-backup-$dstamp
export bundle_path=/tmp/$bundle_dir
export dump_path=/tmp/wiki-backup-$dstamp/hsl_wiki.sql.bz2
export conf_path=/tmp/wiki-backup-$dstamp/LocalSettings.php
export tarball_path=/var/www/static/backups/wiki-backup.tar.bz2
mkdir -p $bundle_path
mysqldump -u wiki_wiki --password=$db_pass hsl_wiki | bzip2 > $dump_path
cp /var/www/mediawiki/LocalSettings.php $conf_path
sed -i s/$db_pass/YOUR_PASSWORD/ $conf_path
tar -C /tmp -cvjf $tarball_path $bundle_dir

Pull Them Somewhere

Backups don't do much good if they're not being stored somewhere. Set up a cron script, maybe on one of HSL's on-prem servers, to periodically pull a copy of the wiki backup.

Test Everything