Configure MediaWiki via LocalSettings.php

Updated on October 17, 2022

Learn how to configure your MediaWiki by changing the LocalSettings.php configuration file.

Configuration on ProWiki

If you are using ProWiki MediaWiki hosting, you will never have to edit LocalSettings.php.

Instead, you can configure your wiki via the admin panel.

What is LocalSettings.php?

LocalSettings.php is the file used by MediaWiki to store configuration settings. It is used to change the default MediaWiki settings. For instance, to change the wiki language from English (the default) to German.

Unlike with some other tools such as WordPress, basic MediaWiki does not come with an admin panel. Thus changing the configuration is rather technical. Firstly, you will need access to the server on which the wiki is hosted. Furthermore, you will need to edit the file itself, which contains PHP. Making small mistakes here can break your wiki.

How to Edit LocalSettings.php

First find the LocalSettings.php file. It is located in the root directory of MediaWiki. Typically at /var/www/html/ or similar.

Option 1: Edit LocalSettings via SSH

If you have SSH access to the wiki server, and are able to use the command line interface, then SSH is a good option.

  1. SSH into the wiki server
  2. Go to the MediaWiki root directory: cd /var/www/html/ (you might need to update this path)
  3. Edit LocalSettings.php with an editor like vim or nano: vim LocalSettings.php

Option 2: Edit LocalSettings on Your Computer

If you do not have SSH access or are not at ease with the command line, then this option is for you. You will still need to be able to change files on the server, for instance via an FTP client.

  1. Get the latest LocalSettings.php file. You might have a local copy already, or need to get it from the server via FTP.
  2. Edit LocalSettings.php with an editor of your choice, such as Notepad++
  3. Save your changes once you are done updating the configuration
  4. Upload LocalSettings.php to your server via FTP or some other method. You should be overriding the old file.

How to Change MediaWiki Configuration

Once you are able to edit LocalSettings.php, it is time to start making configuration changes.

You will be modifying PHP code, so some caution is needed. Small mistakes can bring down your wiki. Luckily you can fix your wiki by undoing the changes that broke it. So if you are not confident about editing correctly, it is a good idea to make a backup copy of the file before you start modifying it. Then you can always switch back to the old version in case things go wrong.

Available Settings

You can find the list of available settings on MediaWiki.org. Also check out the MediaWiki configuration settings category.

If you are using a MediaWiki version older than 1.39, then you can also look at the includes/DefaultSettings.php file. This file lists many of the available settings and sets their default values. Do NOT edit this file, as your changes will then be lost when you upgrade MediaWiki.

Example Change

To change the language of your wiki to German, find the line with $wgLanguageCode and change it to $wgLanguageCode = 'de';

Always make sure you only have one version of the line. If you have multiple copies, then (in most cases) everything except the last copy will be ignored.

If there is no line with $wgLanguageCode yet, simply add it to the end of the file.

Once you saved the LocalSettings.php file on your wiki's server, the changes will immediately be in effect. Simply reload your wiki in your web browser. If your changes do not show up, double check that you spelled the variable name correctly and that there are no extra copies in the LocalSettings.php file.

A slightly more complex example is changing your MediaWiki logo.

How to Enable MediaWiki Extensions

The LocalSettings.php is also where you enable MediaWiki extensions.

Before you can enable a MediaWiki extension, you will have to install it. This means downloading the extension from somewhere, and placing it in the extensions/ directory on the wiki server. A few extensions come bundled with MediaWiki out of the box, so these are already present in the extensions/ directory.

To enable a MediaWiki extension, add the following line to the end of LocalSettings.php:

wfLoadExtension( 'ExtensionName' );

Replace ExtensionName with the name of the extension you wish to enable. This name should be identical to the directory name of the extension in extensions/.

Also see our Installing MediaWiki Extensions with Composer guide.