How to Install and Configure MediaWiki on nixOS Latest

Introduction

MediaWiki is one of the most popular wiki platforms used by millions of people worldwide. It is an open-source software used to create collaboratively edited websites known as wikis. MediaWiki is written in PHP and uses a MySQL/MariaDB database to store content. This tutorial will guide you through the process of installing MediaWiki on nixOS Latest.

Prerequisites

To follow this tutorial, you should be familiar with the Linux command line and have administrative access to your nixOS Latest system. You should also have the following installed:

Step 1: Install Required Dependencies

To install MediaWiki, you need to ensure that your system has PHP, MySQL or MariaDB, and either Apache or Nginx installed. You can install these dependencies by running the following command:

$ sudo nix-env -iA nixos.php nixos.mariadb nixos.nginx

If you prefer Apache over Nginx, you can use the following command:

$ sudo nix-env -iA nixos.php nixos.mariadb nixos.apacheHttpd

Step 2: Install MediaWiki

To install MediaWiki, you can obtain it from the official website. The following command will download and extract the latest stable release:

$ wget https://releases.wikimedia.org/mediawiki/1.36/mediawiki-1.36.2.tar.gz
$ tar -xzvf mediawiki-1.36.2.tar.gz
$ sudo mv mediawiki-1.36.2 /var/www/mediawiki

Step 3: Configure MariaDB or MySQL

MediaWiki requires a database to store its content. You can use either MariaDB or MySQL to create a database.

MariaDB

To install MariaDB, run the following command:

$ sudo nix-env -iA nixos.mariadb

Once installed, start the MariaDB service by running the following command:

$ sudo systemctl start mariadb

Create a new user and database for MediaWiki by running the following commands:

$ sudo mysql -u root
> CREATE DATABASE mediawiki;
> CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'password';
> GRANT ALL PRIVILEGES ON `mediawiki`.* TO 'wikiuser'@'localhost';
> FLUSH PRIVILEGES;
> EXIT;

MySQL

To install MySQL, run the following command:

$ sudo nix-env -iA nixos.mysql

Once installed, start the MySQL service by running the following command:

$ sudo systemctl start mysql

Create a new user and database for MediaWiki by running the following commands:

$ sudo mysql -u root
> CREATE DATABASE mediawiki;
> CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'password';
> GRANT ALL PRIVILEGES ON `mediawiki`.* TO 'wikiuser'@'localhost';
> FLUSH PRIVILEGES;
> EXIT;

Step 4: Configure Apache or Nginx

The next step is to configure either Apache or Nginx to serve MediaWiki. The following configurations assume that MediaWiki is installed in /var/www/mediawiki/ and that you are using MariaDB as your database.

Nginx

Create a new server block in /etc/nginx/sites-available/mediawiki with the following contents:

server {
    listen 80;
    server_name yourdomain.com;

    root /var/www/mediawiki;
    index index.php;

    # MediaWiki rewrite rules
    rewrite ^/wiki(/.*)?$ /index.php?title=$1 last;

    # PHP-FPM configuration
    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param MW_DBNAME mediawiki;
        fastcgi_param MW_DBUSER wikiuser;
        fastcgi_param MW_DBPASSWORD password;
    }
}

Enable the server block by creating a symbolic link in /etc/nginx/sites-enabled/:

$ sudo ln -s /etc/nginx/sites-available/mediawiki /etc/nginx/sites-enabled/

Restart the Nginx service to apply the changes:

$ sudo systemctl restart nginx

Apache

Create a new virtual host in /etc/httpd/conf/vhosts.d/mediawiki.conf with the following contents:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/mediawiki

    <Directory "/var/www/mediawiki">
        AllowOverride All
        Require all granted
    </Directory>

    # MediaWiki rewrite rules
    RewriteEngine On
    RewriteRule ^/?wiki(/.*)?$ /index.php?title=$1 [L,QSA]

    # PHP configuration
    php_value error_reporting 6135
    php_value log_errors_max_len 0
    php_value post_max_size 50M
    php_value upload_max_filesize 50M
    php_value memory_limit -1
    php_value session.gc_maxlifetime 1440
    php_value session.cookie_secure 1

    SetEnv MW_DBNAME mediawiki
    SetEnv MW_DBUSER wikiuser
    SetEnv MW_DBPASSWORD password
</VirtualHost>

Restart the Apache service to apply the changes:

$ sudo systemctl restart apacheHttpd

Step 5: Configure MediaWiki

Open a web browser and navigate to http://yourdomain.com. You should see the MediaWiki installation page.

Follow the on-screen instructions to configure MediaWiki with your database settings.

Once you have completed the installation, MediaWiki will be ready to use.

Conclusion

You have successfully installed and configured MediaWiki on nixOS Latest. With MediaWiki up and running, you can create and manage your own collaborative wiki pages.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!