Install Mediawiki
Setting up your own Mediawiki.
Dependencies
Mediawiki requires 3 things to be installed:
- PHP
- webserver (like nginx or apache)
- database (MariaDB, MySQL, SQLite or PostgreSQL)
Check the Mediawiki download page to see which exact versions you need:
https://www.mediawiki.org/wiki/Manual:Installation_requirements
Install a database
For this example we will use MariaDB
.
$ sudo apt install mariadb-server
Install a webserver
For this example we will use nginx
.
$ sudo apt install nginx
Install PHP
Install PHP
+ the fpm
and php-mysql
extension:
$ sudo apt install php php-common php-fpm php-mysql
Configure your webserver to work with the fpm
extension.
For example, when you work with nginx, edit the default config file with:
$ sudo nano /etc/nginx/sites-enabled/default.conf
and add the following snippet:
Note: change the version number of php to your installed version!
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.3-fpm.sock; }
To see if php works now, you can make a php file in /var/www/html/
called test.php
:
<?php phpinfo(); ?>
Now open this file in the browser and see if it works.
Download Mediawiki
Navigate to the folder where you want to install Mediawiki.
In this example we will install it at /var/www/wiki/
:
cd /var/www/wiki/
Download the latest version of Mediawiki and unzip the tar file.
You can copy the link from the Mediawiki download page: https://www.mediawiki.org/wiki/Download
wget https://releases.wikimedia.org/mediawiki/1.38/mediawiki-1.38.4.tar.gz
tar xf mediawiki-1.38.4.tar.gz
Rename the wiki folder something short, like "wiki".
mv mediawiki-1.35.1 wiki
Configure the URL
To connect the folder /var/www/wiki/
to an url like https://hub.xpub.nl/soupboat/wiki/
we need to edit the configuration file of the webserver.
$ sudo nano /etc/nginx/sites-enables/default.conf
Add the following lines:
location /wiki { alias /var/www/wiki/; index index.php; }
See if it works: https://hub.xpub.nl/soupboat/wiki/
Database
By default you can log in to MariaDB with the root user and the root password.
However, it's a *good idea* to create a dedicated database + database user for your wiki. In this way you can easily back it up (and eventually restore it) with a simple mysqldump
command. Also, it helps to keep different projects separate from each other. See the Mysql page on how to do this. Once you do this add the database name, user name, and password to the Mediawiki setup page when requested.
We will now make a dedicated database for your wiki.
First log in into MariaDB as root:
$ sudo mysql -u root -p
Create a new database:
(Note: replace "<NAMEOFYOURWIKI>" with the name of your wiki, for example: mywiki.)
CREATE DATABASE <NAMEOFYOURWIKI>;
Create a dedicated user for this database and assign a password.
Write this password down, you will need it later to configure the wiki.
(Note: replace "<USERNAME>" and "<SOMEPASSWORD>" with something else.)
CREATE USER '<USERNAME>'@'localhost' IDENTIFIED BY '<SOMEPASSWORD>';
Give this user the rights to edit the database:
GRANT ALL PRIVILEGES ON <USERNAME>.* TO '<USERNAME>'@'localhost';
FLUSH PRIVILEGES;
Exit MariaDB:
quit
Setup your Mediawiki
Now go to the wiki setup script: https://hub.xpub.nl/soupboat/wiki/
(Or wherever you installed your wiki of course!)
In step 2 you can use your database settings as configured in the above step. The database prefix can be left empty.
Give the wiki a name and fill in the administrator account info. When in doubt, leave things at the default values.
At the end, download the "LocalSettings.php" file.
Upload LocalSettings.php
Upload the LocalSettings.php file you just downloaded to the folder of your wiki: /var/www/wiki/
.
The wiki should work now!
Try it out by opening your wiki: https://hub.xpub.nl/soupboat/wiki/
When installing the wiki on a sandbox server
However for a sandbox server you have to tweak one line in the LocalSettings.php file.
Open the file with a text editor (like nano
) and look for:
$wgScriptPath = "/wiki";
and change it to:
$wgScriptPath = "/soupboat/wiki";
Enable uploads
Enable uploads in your LocalSettings.php:
$wgEnableUploads = true; # Enable uploads
and change permissions of the images folder:
$ sudo chgrp www-data /var/www/wiki/images $ sudo chmod 775 /var/www/wiki/images
From: https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
Configure
How open/closed do you want your wiki to be?
- public, everyone can edit
- public, only people with accounts can edit, account creation is open
- public, only people with accounts can edit, account creation is closed
- non-public, only you can edit
...
Back up your wiki
...
Extensions
...
Skins
...