How to install MediaWiki 1.34.2 on Ubuntu Server 20.04 LTS

Post Reply
User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

How to install MediaWiki 1.34.2 on Ubuntu Server 20.04 LTS

Post: # 908Post LHammonds »

WORK-IN-PROGRESS --------- WORK-IN-PROGRESS

Greetings and salutations,

I hope this thread will be helpful to those who follow in my foot steps as well as getting any advice based on what I have done / documented.

To discuss this thread, please participate here: >> CREATE FORUM LINK <<

High-level overview

This thread will cover install and configuration of a MediaWiki web site on a dedicated Ubuntu server and will utilize a separate dedicated database server. The server will be installed inside a virtual machine vSphere running on ESXi servers. Although there are some VMware-specific steps, they are very few and the majority of this documentation will work for other environments such as VirtualBox, Proxmox or even directly installed onto a physical machine. Please excuse any ignorance on my part and if you have any advice on doing things better, please let me know. I love feedback and learning better ways of doing things!

After Ubuntu is installed and configured, Apache web server will be installed and configured. Next will be the installation and configuration of MediaWiki which will utilize an existing remote database server (MariaDB/MySQL). Some extensions will then be installed and tested.

The last step will cover some custom scripts to help automate tasks such as backing up, automatically growing the file system when free space is low, etc.

Tools utilized in this process
Helpful links

The list below are sources of information that helped me configure this system as well as some places that might be helpful to me later on as this process continues.
Assumptions

This documentation will need to make use of some very-specific information that will most-likely be different for each person / location. And as such, I will note some of these in this section. They will be highlighted in red throughout the document as a reminder that you should plug-in your own value rather than actually using my "place-holder" value.

Under no circumstance should you use the actual values I list below. They are place-holders for the real thing. This is just a checklist template you need to have answered before you start the install process.

Wherever you see RED in this document, you need to substitute it for what your company uses. Use the list below as a template you need to have answered before you continue.
  • Ubuntu Server name: srv-wiki
  • Internet domain: mydomain.com
  • Ubuntu Server IP address: 192.168.107.30
  • Ubuntu Admin ID: administrator
  • Ubuntu Admin Password: myadminpass
  • Email Server (remote): 192.168.107.25
  • MySQL Server (remote): 192.168.107.20
  • MySQL root Password: mysqlrootpass
  • MySQL wiki user: mediawikiuser
  • MySQL wiki Password: mediawikiuserpass
  • Windows Share ID: mediawikishare
  • Windows Share Password: mywikisharepass
Web Server - Setup an Ubuntu server for use as the MediaWiki server. This tutorial assumes the server was configured according to this tutorial: How to install Apache web server

MySQL/MariaDB server - Setup a separate and dedicated database server. This tutorial assumes the server was configured according to this tutorial: How to install and configure MariaDB

I also assume the reader knows how to use the VI editor. If not, you will need to beef up your skill set or use a different editor in place of it.

User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Configure MariaDB / MySQL

Post: # 909Post LHammonds »

Configure MariaDB / MySQL

In this scenario, a dedicated and general-purpose database server already exists and it will be used to hold the application's database.
  1. Connect to the MariaDB/MySQL server using PuTTY.
  2. At the login prompt, login with your administrator account (administrator / myadminpass) and then temporarily grant yourself super user privileges by typing sudo su
  3. Type the following commands:
    mysql -u root -p Enter password: rootpass
    CREATE DATABASE mediawiki CHARACTER SET utf8 COLLATE utf8_bin; CREATE USER 'mediawikiuser'@'%' IDENTIFIED BY 'mediawikiuserpass'; GRANT ALL ON mediawiki.* TO 'mediawikiuser'@'%'; FLUSH PRIVILEGES; exit
    The above commands will allow the database account to connect from any machine from anywhere in the world. This might be OK if your database is not accessible outsite your local network or if your machine name changes or you have multiple servers that connect to the same database that use the same ID. You can make this more secure by specifying your application server when granting access. Make sure the database server will recognize the server name (via hosts file or DNS) or just use the IP address:
    CREATE USER 'mediawikiuser'@'srv-mediawiki' IDENTIFIED BY 'mediawikiuserpass'; GRANT ALL ON mediawiki.* TO 'mediawikiuser'@'srv-mediawiki';
    or
    CREATE USER 'mediawikiuser'@'192.168.107.30' IDENTIFIED BY 'mediawikiuserpass'; GRANT ALL ON mediawiki.* TO 'mediawikiuser'@'192.168.107.30';
    This will prevent anyone knowing the credentials from logging into the database from any other remote machine not specified in the grant command.

    If your application is running on the database server (typical on a developer machine / non-production scenario), create the user like this:
    CREATE USER 'mediawikiuser'@'localhost' IDENTIFIED BY 'mediawikiuserpass'; GRANT ALL ON mediawiki.* TO 'mediawikiuser'@'localhost';
    This will prevent anyone knowing the credentials from logging into the database from any other remote machine.

    If you mess anything up, you can remove the database and user by issuing these commands:
    DROP USER mediawikiuser; FLUSH PRIVILEGES; DROP DATABASE mediawiki;

User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Prerequisites

Post: # 910Post LHammonds »

Add Non-SSL Apache Site Configuration

Refer to this tutorial but substitute the example domain name and path for your domain.

Add SSL Apache Site Configuration

Please refer to this tutorial but substitute the example domain name and path for your domain.

MediaWiki Prerequisites
  1. At the server console, type the following to install the additional modules and restart the web service :

    Code: Select all

    sudo apt install php7.4-mysql php7.4-gd php7.4-intl php7.4-curl php7.4-mbstring php7.4-xml imagemagick
    sudo systemctl restart apache2
  2. To make sure the modules are loaded, we will create a phpinfo file:

    Code: Select all

    sudo touch /var/www/wiki.mydomain.com/phpinfo.php
    sudo chown www-data:www-data /var/www/wiki.mydomain.com/phpinfo.php
    sudo chmod 0644 /var/www/wiki.mydomain.com/phpinfo.php
    echo "<?php phpinfo(); ?>" >> /var/www/wiki.mydomain.com/phpinfo.php
    
  3. Now open a web browser and go to http://192.168.107.23/phpinfo.php or http://wiki.mydomain.com/phpinfo.php and verify that all the MediaWiki required modules are present.
  4. When satisfied everything is good, delete the test files:

    Code: Select all

    sudo rm /var/www/wiki.mydomain.com/index.html
    sudo rm /var/www/wiki.mydomain.com/phpinfo.php

User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Install MediaWiki

Post: # 911Post LHammonds »

Install MediaWiki

At the time of this writing, MediaWiki's current version is 1.34.2 so we will be downloading and installing that archive.
  1. Connect to the MediaWiki server using PuTTY.
  2. At the login prompt, login with your administrator account (administrator / myadminpass)
  3. Type the following:

    Code: Select all

    cd /tmp
    wget https://releases.wikimedia.org/mediawiki/1.34/mediawiki-1.34.2.tar.gz
    sudo tar -xzvf /tmp/media*.gz -C /var/www/wiki.mydomain.com/ --strip-components=1
    sudo chown www-data:root --recursive /var/www/wiki.mydomain.com/*
    sudo find /var/www/wiki.mydomain.com/. -type d -exec chmod 755 '{}' \+
    sudo find /var/www/wiki.mydomain.com/. -type f -exec chmod 644 '{}' \+
    rm /tmp/media*.gz
    
  4. Tighten security on the "images" upload folder. Type the following:

    Code: Select all

    sudo vi /etc/apache2/sites-available/wiki.mydomain.com.conf
    Add the following:

    Code: Select all

      <Directory "/var/www/wiki.mydomain.com/images">
        # Ignore .htaccess files
        AllowOverride None
        # Serve HTML as plaintext, don't execute SHTML
        AddType text/plain .html .htm .shtml .php
        # Don't run arbitrary PHP code.
        php_admin_flag engine off
        # If you've other scripting languages, disable them too.
      </Directory>
    Example configuration:

    Code: Select all

    <VirtualHost *:80>
      ServerAdmin webmaster@localhost
      DocumentRoot /var/www/wiki.mydomain.com
      ErrorLog ${APACHE_LOG_DIR}/wiki-error.log
      CustomLog ${APACHE_LOG_DIR}/wiki-access.log combined
      AddType image/x-icon .ico
      <Directory "/var/www/wiki.mydomain.com/images">
        # Ignore .htaccess files
        AllowOverride None
        # Serve HTML as plaintext, don't execute SHTML
        AddType text/plain .html .htm .shtml .php
        # Don't run arbitrary PHP code.
        php_admin_flag engine off
        # If you've other scripting languages, disable them too.
      </Directory>
    </VirtualHost>
  5. Restart the web service:

    Code: Select all

    sudo systemctl restart apache2
  6. Open a browser and go to http://192.168.107.23/index.php or http://wiki.mydomain.com/index.php, click on the "set up the wiki" link when the page loads.
  7. Installation Language - Click Continue to accept en-English
  8. Environmental Checks - Click Continue
  9. Connect to database - Set the following and click Continue:
    Database type: MariaDB, MySQL, or compatible
    Database host: 192.168.107.20
    Database name: mediawiki
    Database table prefix:
    Database username: mediawikiuser
    Database password: mediawikiuserpassword
  10. Database settings - Set the following and click Continue:
    Check - Use the same account as for installation
  11. Name - Set the following and click Continue:
    Name of wiki: MyWiki
    Project namespace: Same as the wiki name
    Your Name: JohnDoe
    Password: Hobo123!
    Password again: Hobo123!
    E-mail address: JohnDoe@mydomain.com
    Uncheck: Subscribe to the release announcements mailing list
    Uncheck: Share data about this installation with MediaWiki developers
    Check: Ask me more questions
  12. Options - Set the following and click Continue:
    User rights profile: Account creation required (or whatever your preference)
    Copyright and license: No license footer
    EMAIL SETTINGS
    Check: Enable outbound e-mail
    Return e-mail address: no-reply@mydomain.com
    Check: Enable user-to-user e-mail
    Check: Enable user talk page notification
    Check: Enable watchlist notification
    Check: Enable e-mail authentication
    SKINS
    Check: CologneBlue
    Check: Modern
    Check: MonoBook (Use this skin as default)
    Check: Vector
    EXTENSIONS
    Check: CiteThisPage
    Uncheck: Interwiki (* NOTE: This is not needed if you are only hosting one wiki *)
    Uncheck: Nuke
    Check: Renameuser (* NOTE: Do not enable if you plan to use external LDAP authentication *)
    Check: ReplaceText
    Check: CodeEditor (requires WikiEditor)
    Check: WikiEditor
    Check: CategoryTree
    Check: Cite
    Check: ImageMap
    Check: InputBox
    Check: ParserFunctions
    Check: Poem
    Check: Scribunto
    Check: SyntaxHighlight_GeSHi
    Check: PdfHandler
    Check: ConfirmEdit
    Check: SpamBlacklist
    Check: TitleBlacklist
    Check: Pageimages
    Check: Gadgets
    Uncheck: LocalisationUpdate
    Check: MultimediaViewer
    Uncheck: OATHAuth
    Check: TextExtracts

    IMAGES AND FILE UPLOADS
    Check: Enable file uploads
    Directory for deleted files: /var/www/wiki.mydomain.com/images/deleted
    Logo URL: $wgResourceBasePath/resources/assets/mylogo.png
    Uncheck: Enable Instant Commons
    ADVANCED CONFIGURATION
    Check: No caching
  13. Install Confirmation - Click Continue
  14. Install Done - Click Continue
  15. Save the LocalSettings.php to your PC.
  16. On the server console, type the following:

    Code: Select all

    sudo touch /var/www/wiki.mydomain.com/LocalSettings.php
    sudo chown www-data:root /var/www/wiki.mydomain.com/LocalSettings.php
    sudo chmod 0600 /var/www/wiki.mydomain.com/LocalSettings.php
    sudo vi /var/www/wiki.mydomain.com/LocalSettings.php
    
  17. Copy and paste the contents of the LocalSettings.php you downloaded just a moment ago into this editor above. Save and exit the editor.
  18. Increase the php filesize limit of uploaded files by editing /etc/php/7.4/apache2/php.ini and find upload_max_filesize and change it from 2M to 50M, then find post_max_size and change it from 8M to 51M
  19. Increase the wiki filesize limit of uploaded files by editing /var/www/wiki.mydomain.com/LocalSettings.php and add the following line: $wgMaxUploadSize = '52428800'; (Reference)
  20. Allow various file types to be uploaded and certain file types to be blocked by editing /var/www/wiki.mydomain.com/LocalSettings.php and add the following lines:

    Code: Select all

    # Allow the files to be uploaded with the following extensions:
    $wgFileExtensions[] = 'bmp';
    $wgFileExtensions[] = 'doc';
    $wgFileExtensions[] = 'docx';
    $wgFileExtensions[] = 'gif';
    $wgFileExtensions[] = 'jpg';
    $wgFileExtensions[] = 'jpeg';
    $wgFileExtensions[] = 'mp3';
    $wgFileExtensions[] = 'mpp';
    $wgFileExtensions[] = 'odt';
    $wgFileExtensions[] = 'ods';
    $wgFileExtensions[] = 'odp';
    $wgFileExtensions[] = 'odg';
    $wgFileExtensions[] = 'pdf';
    $wgFileExtensions[] = 'ppt';
    $wgFileExtensions[] = 'pptx';
    $wgFileExtensions[] = 'ps';
    $wgFileExtensions[] = 'png';
    $wgFileExtensions[] = 'tiff';
    $wgFileExtensions[] = 'xls';
    $wgFileExtensions[] = 'xlsx';
     
    # Block files from being uploaded with the following extensions:
    $wgFileBlacklist[] = 'exe';
    $wgFileBlacklist[] = 'php';
    $wgFileBlacklist[] = 'sh';
    $wgFileBlacklist[] = 'com';
    $wgFileBlacklist[] = 'vbs';
    $wgFileBlacklist[] = 'bat';
    $wgFileBlacklist[] = 'htm';
    $wgFileBlacklist[] = 'html';
    $wgFileBlacklist[] = 'js';
    
  21. Edit /var/www/wiki.mydomain.com/LocalSettings.php and add the following line:

    Code: Select all

    $wgFavicon = "$wgScriptPath/favicon.ico";
  22. Create a logo image in PNG format that has the dimensions of 135 x 133 pixels. Save it to \\192.168.107.23\share\mylogo.png
  23. On the server console, type the following:

    Code: Select all

    mv /srv/samba/share/mylogo.png /var/www/wiki.mydomain.com/resources/assets/.
    chown www-data:root /var/www/wiki.mydomain.com/resources/assets/mylogo.png
    chmod 0644 /var/www/wiki.mydomain.com/resources/assets/mylogo.png
    
  24. Edit /var/www/wiki.mydomain.com/LocalSettings.php and add the following lines (preferably after the existing email variables):
    $wgSMTP = array( 'host' => "mail.mydomain.com", //could also be an IP address 'IDHost' => "mydomain.com", 'port' => 25, 'auth' => true, 'username' => "my_smtp_username", 'password' => "my_smtp_password" );
  25. To enable the WikiEditor by default, edit /var/www/wiki.mydomain.com/LocalSettings.php and add the following lines (preferably right after WikiEditor extension line):

    Code: Select all

    $wgDefaultUserOptions['usebetatoolbar'] = 1;
    $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
    $wgDefaultUserOptions['wikieditor-preview'] = 1;
    $wgDefaultUserOptions['forceeditsummary'] = 1;
    
  26. NOTE: To see a list of other preferences you can set by default, look at this page or run the following command:

    Code: Select all

    php /var/www/wiki.mydomain.com/maintenance/userOptions.php --list
  27. To set configure some settings for the ConfirmEdit extension, edit /var/www/wiki.mydomain.com/LocalSettings.php and add the following lines (preferably after the ConfirmEdit extension line):

    Code: Select all

    $wgCaptchaTriggers['edit']          = true;
    $wgCaptchaTriggers['create']        = true;
    $wgCaptchaTriggers['addurl']        = true;
    $wgCaptchaTriggers['createaccount'] = true;
    $wgCaptchaTriggers['badlogin']      = true;
    $wgGroupPermissions['emailconfirmed']['skipcaptcha'] = true;
    $ceAllowConfirmedEmail = true;
    
  28. Restart the Apache web service

    Code: Select all

    sudo systemctl restart apache2
  29. Visit http://192.168.107.23 or http://wiki.mydomain.com
  30. You should see your wiki page with your custom logo. Test your login ID that you created earlier.

User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Upgrading MediWiki

Post: # 912Post LHammonds »

Upgrading MediWiki

Please refer to the MediaWiki Upgrade instructions as they are your primary source of information.

The documentation below is what I did to upgrade a MediaWiki 1.25.1 instance to 1.28.0
  1. Make sure you have a recent backup of the MediaWiki site and its database.
  2. Setup the new version in a different folder by typing the following:

    Code: Select all

    sudo mkdir -p /var/www/newwiki
    cd /tmp
    wget https://releases.wikimedia.org/mediawiki/1.28/mediawiki-1.28.0.tar.gz
    sudo tar -xzvf /tmp/media*.gz -C /var/www/newwiki/ --strip-components=1
    rm /tmp/media*.gz
    
  3. Copy over the important bits from the current production version:

    Code: Select all

    sudo cp -p /var/www/wiki.mydomain.com/LocalSettings.php /var/www/newwiki/.
    sudo cp -R -p /var/www/wiki.mydomain.com/images/* /var/www/newwiki/images/.
    sudo cp -p /var/www/wiki.mydomain.com/resources/assets/*logo* /var/www/newwiki/resources/assets/.
  4. Ensure all permissions and ownership are correctly set:

    Code: Select all

    sudo chown www-data:root --recursive /var/www/newwiki/*
    sudo find /var/www/newwiki/. -type d -exec chmod 755 '{}' \+
    sudo find /var/www/newwiki/. -type f -exec chmod 644 '{}' \+
  5. Swap the folders so the old code goes away and the new code becomes visible:

    Code: Select all

    sudo mv /var/www/wiki.mydomain.com/var/www/oldwiki
    sudo mv /var/www/newwiki /var/www/wiki.mydomain.com
  6. Run the upgrade code:

    Code: Select all

    sudo php /var/www/wiki.mydomain.com/maintenance/update.php

User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Add More Extensions

Post: # 913Post LHammonds »


User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Add More Skins

Post: # 914Post LHammonds »


User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Scripting

Post: # 915Post LHammonds »

Scripting

Much of the solutions beyond this point involve scripts (programming snippets / automated commands).

In particular, they are Bash Scripts. I chose this due to its popularity and the fact it comes with Ubuntu. I try to make use of what comes with the system without requiring additional software / services unless they really add to the bottom line such as decreasing the time it takes for a process to run or to conserve storage and bandwidth usage.

Ondemand Database Backup

My database server exports all databases and archives them on a normal schedule so any database I add to it such as the mediawiki database will get included automatically.

However, I created another script designed to run every minute looking for key files. If a specific file shows up on the samba share, it will trigger an immediate backup of the specified database. This will be helpful when scheduling the backup of the MediaWiki web files. When the web backup script run, it will place the database-specific file on the remote database server's samba share which will trigger the database backup to run immediately. The web backup script can trigger the remote database backup anytime it runs no matter if it is schedule via crontab or manually run.

Here is the script that runs every minute on the database server:

/var/scripts/prod/db-ondemand-backup.sh (GitHub)

Code: Select all

>> REWRITE IN PROGRESS <<
Here is a sample of the log file:

/var/log/abc-db-ondemand-backup.log

Code: Select all

>> REWRITE IN PROGRESS <<

User avatar
LHammonds
Site Admin
Site Admin
Posts: 913
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

MediaWiki Backup

Post: # 916Post LHammonds »

MediaWiki Backup

There are various methods of backup that can be utilized but for this server, I will simply use RSync and tar.

RSync will mirror the files in the production folder to a local backup folder. The archive will be created from this backup folder.

Here are the folders I consider important that will be included in the backup:

Data Folders:
SRV-Wiki: /bak (which contains a mirror of /var/www/wiki.mydomain.com)

Config Folders and files:
SRV-Wiki: /var/log/apache2/
SRV-Wiki: /etc/apache2/
SRV-Wiki: /etc/php/
SRV-Wiki: /etc/netplan/
SRV-Wiki: /etc/hosts

Remote Data:
srv-database: MediaWiki Database

The backup of the web site will be fairly simplistic. However, since there are multiple servers involved, the backup will need to be synchronized for the web files, uploads and the remote database.

A crontab schedule will be used to schedule the local backups and when the backup is initiated on the local server, a special file will be sent to the remote database server so it will trigger a backup on the database that corresponds to this server (mediawiki).

The bulk of the data will be in /var/www and rsync will be used to copy any files from that folder to the backup folder. The benefit and beauty of using rsync in this way is that it will only copy what has changed since the last backup/sync. That means it will run VERY quickly even if your www folder has gigs of data in it. The other miscellaneous folders will be archived directly from their source location which will not be much in terms of size.

/var/scripts/prod/mediawiki-backup.sh (GitHub)

Code: Select all

>> REWRITE IN PROGRES <<
Here is some sample output from the log file.

/var/log/abc-mediawiki-backup.log

Code: Select all

>> REWRITE IN PROGRES <<

Post Reply