How to set up MediaWiki

Revision as of 20:05, 19 September 2022 by HolyNetworkAdapter (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

MediaWiki is wiki software which many wikis, including the Computernewb Wiki and Wikipedia, use to provide an easy way to host a collaborative encyclopedia. Here, you can learn how to install it.

You are advised to use MediaWiki 1.38.2, as that is the latest version as of September 2022.

Prerequisites

 
MediaWiki may not work properly on PHP versions 7.4.0 to 7.4.2. You should use the latest PHP version.

You will need the following software to host a MediaWiki server:

Type/Name Recommended Alternatives
Web server Apache nginx, lighttpd
SQL database MySQL MariaDB, PostgreSQL, SQLite
PHP PHP 7.4.3 N/A

It is also recommended to use the PHP intl extension. If you do not, a warning will show up in the MediaWiki installer, but you will still be able to proceed with the installation.

Downloading MediaWiki

You can download MediaWiki in two ways: from the website as a zip or tar.gz file or from MediaWiki's official actively updated Git repository.

From the website

Simply go to the official download page and press "Download MediaWiki a.bc.d."

From the Git repository

You can clone the entire repository or just the most recent version.

Entire repository:

git clone https://gerrit.wikimedia.org/r/mediawiki/core.git

Latest revision:

git clone --depth 1 https://gerrit.wikimedia.org/r/mediawiki/core.git

Preparing for installation

From this point on, the tutorial will be assuming you are using Apache, MySQL, and an OpenRC/sysvinit-based init.

Now that MediaWiki has been downloaded, you need to prepare for it by creating a MySQL database.

If you downloaded MediaWiki through the website, you'll need to unzip it first. It is easier to extract the contents of the zip or tar.gz file to the directory your server software hosts.

We'll need to configure the database. Start by starting your SQL service and creating a database:

[root@myBox]# mysqld &
[root@myBox]# mysql
mysql >

In the MySQL prompt, type this in to create your database:

CREATE DATABASE wiki;
CREATE USER 'userforwiki'@'localhost' IDENTIFIED BY 'changeThisPassword';
GRANT ALL PRIVILEGES ON wiki.* TO 'userforwiki'@'localhost' WITH GRANT OPTION;

Finally, start your web server service:

[root@myBox]# /etc/init.d/apache2 start

Installation

Note: In order to navigate to a file on your computer, you should use file://. For example, to go to /home/user, you use file:///home/user. Make sure to include the third slash; that represents the root directory!

Now, you can finally install MediaWiki. First, go into your browser. Navigate to index.php, which is located in the location of the MediaWiki folder. You should see a message telling you to set up MediaWiki by going to a link. Click on the link and fill out the form. You can skip the last page, which lets you install some common extensions and skins for MediaWiki.

When you have finished the form, you will see a page that asks you to download a file named LocalSettings.php. You must download this file, or else you will have to redo the installation form. Place the file where your index.php file is. After moving the file there, reload the page. Success! You've created your first wiki.

Configuration

Now that you've gotten MediaWiki set up, you might as well configure it.

Restricting access to edit the main page

By default, the main page isn't protected. Log in with the administrator account you created during setup, and click on the arrow by the top right of the page. Find the option to "protect" the page, and click that. The main page is now no longer editable to anybody but administrators.

Enabling short URLs

Some wikis, like Wikipedia, have short URLs enabled. This allows URLS to not require the .php file extension. In your LocalSettings.php file, add this:

$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

If you use Apache, your /etc/apache2/vhosts.d/default_vhost.include file will need to contain this (at least on Gentoo):

RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/YourMediaWikiDir/index.php [L]

Otherwise, you will need to find a way to configure short URLs for your server.

Changing the main icon

In order to change the main icon, put an icon in your MediaWiki folder and add a configuration to your LocalSettings.php file like this:

$wgLogo = "/YourMediaWikiDir/myWikiLogo.png";

Changing the favicon

If you want to change the favicon, you can add this to LocalSettings.php:

$wgFavicon = "/YourMediaWikiDir/myWikiIcon.ico";

What should I do next?