Creating And Configuring MediaWiki

From Nick's Personal Wiki
Jump to navigation Jump to search

Prerequisites

A server with the LAMP stack is required to run MediaWiki, a Wiki on how to accomplish that can be found here. If the server to be used already has the LAMP stack installed and running, this Prerequisites section can be skipped.

Installing The Correct Packages For PHP

As of writing, MediaWiki requires PHP 7.3.19-24, 7.4.3, or later and will need to be installed manually.

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf module reset php
sudo dnf module install php:remi-8.0 

Install the module to support the use of MariaDB:

sudo dnf install php-mysqlnd  

This may already be installed on the server, if so you can move on to the next step without issue.

Restart the Apache httpd.service for the changes to take effect:

sudo systemctl restart httpd.service 

Creating A Database for MediaWiki

This guide assumes that MariaDB has already been installed using the LAMP stack Wiki tutorial linked in Prerequisites above, an d will begin by creating a database to be used by MediaWiki.

Log into the MariaDB console using the below:

sudo mysql -u root -p 

Provide the root credentials for MariaDB that were created when installing MariaDB.

Create the database MediaWiki will use:

create database WIKI_NAME;

Create a user to manage the database MediaWiki will use:

create user 'EXAMPLE_USER'@'localhost' identified by 'PASSWORD';

Give this new user permissions to access the database MediaWiki will use:

grant all privileges on WIKI_NAME.* to 'EXAMPLE_USER'@'localhost' with grant option;

Exit the MariaDB console via:

exit;


Downloading MediaWiki

The latest release of MediaWiki can be downloaded manually from here (MediaWiki Downloads Page), the latest release with the .tar.gz extension is the desired option for this tutorial.

mediawiki-VERSION will be used as a placeholder name for the mediawiki files, replace VERSION with the latest version that is being downloaded in the following commands.

This release can also be downloaded from the command line on the remote server via the 'wget' tool:

wget https://releases.wikimedia.org/mediawiki/VERSION/mediawiki-VERSION.tar.gz

However the files were retrieved, move the downloaded files to the Apache document directory (typically '/var/www/html/' or wherever is specified in the '/etc/httpd/conf/httpd.conf' file):

sudo mv mediawiki-VERSION.tar.gz /var/www/html/

Navigate to the document directory those files were relocated, in this tutorial's case '/var/www/html':

cd /var/www/html/

Extract the files from the downloaded tarball:

sudo tar xvzf /var/www/html/mediawiki-VERSION.tar.gz

Extracting this tarball using sudo will make the root user the owner of the files, if another outcome is desired, the 'chown' command can be used to correct this.

If the 'tar' command is not installed on the server:

sudo dnf install tar

Rename the extracted folder to whatever is desired, knowing that the name of this folder will be included in all URL's for this Wiki:

sudo mv /var/www/html/mediawiki-VERSION /var/www/html/wiki

In this case, 'wiki' will be included in all URLs for this Wiki, i.e.:

 http://www.example.com/wiki/example


Installing MediaWiki

From a web browser the below URL should now be accessible to configure the MediaWiki installation via the webGUI:

http://wwww.EXAMPLE.com/wiki/index.php
or
http://A.B.C.D/wiki/index.php

Follow the setup link and navigate through the setup steps until prompted for a database to be provided. Provide the MariaDB database name, username, password for that user.

When setup is complete, MediaWiki will generate a LocalSettings.php file that needs to be downloaded to the server for use.

This can be downloaded to a local machine and copied to the remote server for use via the below:

scp /path/to/downloaded/LocalSettings.php USER@A.B.C.D:/path/to/destination/file

Once the file is on the remote server, move it to the WikiMedia directory:

sudo mv /path/to/LocalSettings.php /var/www/html/wiki/LocalSettings.php

The permissions for this file will need to be adjusted via the below:

sudo chmod 664 /var/www/html/wiki/LocalSettings.php

Ownership of the file may also need to be corrected via:

sudo chown USER:USER LocalSettings.php

If all of the above has been done correctly, navigating to the index.php file again should present the MediaWiki installation.

http://wwww.EXAMPLE.COM/wiki/index.php
or
http://A.B.C.D/wiki/index.php


Changing The Logo In The Upper Left

To change the image in the upper left corner of the Main Page and all other pages on the Wiki, the desired image needs to be uploaded to the server and placed in the '/wiki/images' directory.

For best results, the image should be no larger than 135x135 pixels in size and be .png, .svg, or .jpeg filetypes.

To accomplish uploading the desired image to the server, the below command can be used:

scp /path/to/desired/image.png USER@A.B.C.D:/path/to/destination

If the image was not placed in the '/wiki/images' directory already, the following command will relocate it to the correct directory:

mv /path/to/desired/image.png /path/to/wiki/images/image.png

Then navigate within the server to the LocalSettings.php file placed on the server in the steps above. This will be located at '/wiki/LocalSettings.php' by default.

In this file, add the below to the bottom of the LocalSettings.php file:

$wgLogo = "{wgScriptPath}/images/IMAGE_NAME.[png, svg, jpeg]";

Using ONLY the correct file format for the file that has been uploaded.

Once the image is in the correct directory and the LocalSettings.php file is pointing to its correct location with the $wgLogo variable, clearing the cache on the browser and reloading the Wiki should show the new image in the upper left.

If additional documentation for the Logo is needed, see here.

Potential Suggestions

There may also be a need to run the below command to reset the security context for SELinux on the LocalSettings.php file in order for it to work correctly. This can be done via:

sudo restorecon -r /var/www/html/wiki


Additional Resources

MediaWiki Documentation Wiki