MediaWiki - Applying Minor Revision Updates

Below is the process that I have been using to apply minor updates to MediaWiki. I hope you find it useful, please send me any questions or comments, I read them all and will respond.

Please note that the upgrade procedure is not for major version upgrades as there are significant requirements and other changes between major releases. As the current major version of MediaWiki is 1.35, these steps will work for updating v1.35.x. When the update is completed, the MediaWiki version will be 1.35.2 as of this writing. These steps should work for applying other minor updates, within the major version.

Update: Applying major updates is functionally the same and is outlined here at https://staging-forum.lawrencesystems.com/t/mediawiki-applying-major-revision-updates/10281

My MediaWiki Server Environment

  • Debian 10
  • Apache2 ( latest version)
  • MariaDB or My SQL (latest version)
  • PHP 7.3.28 (NOTE there are major compatibility issues with later versions of PHP, per MediaWiki foundation)

Layout of my MediaWiki install

  • My MediaWiki server is on a dedicated VM instance and there are no other websites or services installed
  • The MediaWiki (live) website is installed at - /var/www/html/
  • For updates and upgrades, I use a dedicated working directory at /var/www/mw
  • I do this to keep things organized and tidy
  • After the upgrade or update, I keep the archive in the /mw directory for reference to know exactly what version is currently installed without needing to go thru the website
  • After upgrade, I do remove previous update/upgrade version archives in the /mw directory
  • I don’t use root so all the commands will use SUDO. If you run as root, modify commands accordingly

Best Practice Recommendations Before Upgrading

  • Update the system (sudo apt update && sudo apt upgrade)
  • If the system has been up for a long time, reboot the system before upgrading
  • Backup the system
  • If this is a VM, snapshot creation before updating is sufficient. If something goes wrong, you can roll back
  • If this is a bare metal installation, recommend backup of the database as it contains all the info from your MediaWiki site

Optional - Verify the current version of MediaWiki from within your MediaWiki website instance

  • Log into your MediaWiki website with an admin user and navigate to Special pages → Version (under data and tools section) - At the top under installed software section you should see MediaWiki and the new version next to it.

TL;DR Update Commands
Source - Manual:Upgrading - MediaWiki
sudo systemctl stop apache2
sudo cp /var/www/html/LocalSettings.php /var/www/html/LocalSettings.php.bak
cd /var/www/mw
sudo wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.tar.gz
sudo tar xvzf mediawiki-1.35.2.tar.gz -C /var/www/html/ --strip-components=1
cd /var/www/html/maintenance
sudo ./update.php
sudo systemctl start apache2
sudo rm /var/www/mw/mediawiki-1.35.1.tar.gz

Long Form Update Process with Step-by-Step and Explanations

1. Update Process

  • From the terminal, navigate to the /mw working directory
  • If you don’t have this, it can be created with the command sudo mkdir /var/www/mw
  • To navigate into the working directory using cd /var/www/mw
  • In the /mw working directory, I list out the current contents with ls -la

2. Stopping the Apache web service

  • Make sure all users are off of your MediaWiki site
  • Stop the Apache2 service with sudo systemctl stop apache2
  • If you want to see the status of the Apache service, use sudo systemctl status apache2, it should say stopped

3. Make a copy of the LocalSettings.php file

  • The LocalSettings.php file is a critical file containing the configuration for your entire MediaWiki website
  • Getting a quick copy of the LocalSettings.php file is strongly recomended
  • To make a copy of the file, use the cp command. My MediaWiki install is located in /var/www/html so the LocalSettings.php file is in there
  • to make a copy I use the command sudo cp /var/www/html/LocalSettings.php /var/www/html/LocalSettings.php.bak
  • A copy of the LocalSettings.php file has been created and has the .bak for the file extension. If you want to verify it use the ls -la /var/www/html command to see that it is present

4. Download the MediaWiki update

  • Should be in the /mw working directory, if you need to check either look at path in the terminal or use the pwd command
  • to download the update, we will use wget to pull it from MediaWiki repository
  • If wget is not installed use the following command to install it and the https transport for apt. The install command is sudo apt install wget apt-transport-https
  • Downloading the current version of MediaWiki is info is here at https://www.mediawiki.org/wiki/Manual:Upgrading#Command_line
  • As of this writing, version 1.35.2 is what we will be updating, so to get it we use the command wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.tar.gz
  • When completed the archive will be in the /mw working directory and can be listed with the ls -la command

5. Installing the MediWiki update

  • We should be in the /mw working directory. The next command will unpack and copy over the update to the installed (live) directory of the MediaWiki install. For my server, the MediaWiki install lives at /var/www/html so my command will include this path. If your install is somewhere else, you will need to modify the command
  • the command to install the update is sudo tar xvzf mediawiki-1.35.2.tar.gz -C /var/www/html/ --strip-components=1
  • NOTES: The link provided earlier to MediaWiki on updating includes a different command to deflate the archive. Their version has not ever worked for any of the updates I have ever applied on any of my Debain based builds. The provided command in the line above is correct and gets the job done
  • NOTES: The above command is the same command used for building new MW servers too
  • Now that the command is completed, we need to run the update for PHP to complete the install. Don’t skip this setup, you’re only half done.

6. Updating PHP to complete the update

  • Now we need to make PHP look at the update to complete the changes and get the MediaWiki server back to working order
  • Currently we are in the /mw working directory. We can either run the next command from here or change to the maintenance directory and run the update from there
  • (optional) list the contents of the MediaWiki install directory using ls -la /var/www/html - You should see a directory called maintenance
  • (optional) list the contents of the MediaWiki maintenance directory using ls -la /var/www/html/maintenance - In this directory, you should see a file named update.php
  • Running the update from the /mw directory - sudo /var/www/html/maintenance/update.php
  • (optional) running the update from within the maintenance directory (cd /var/www/html/maintenance) sudo ./update.php
  • The update will take a few seconds to run

7. Restart the Apache service and check the MediaWiki version from the website

  • Restart the Apache2 service with sudo systemctl start apache2
  • (optional) if you want to verify the apache2 service is running use sudo systemctl status apache2 for verification
  • Open your MediaWiki server page and log in with an admin account.
  • To verify the version navigate to Special pages → Version (under data and tools section) - At the top under installed software section you should see MediaWiki and the new version next to it
  • Congratulations, you have updated your MediaWiki server

8. House Keeping

  • Delete the previous versions of updates or if you don’t want to keep the current update archive you can remove it too. In this example I remove the previous update file (1.35.1) from the /mw working directory
  • If you are not in the /mw directory you can either go there with cd /var/www/mw or you can issue the command with the path. If you need to know the name of the file to remove, use the ls -la /var/www/mw to list the contents
  • to remove the old update archive use sudo rm mediawiki-1.35.1.tar.gz while in the /mw directory or use sudo rm /var/www/mw/mediawiki-1.35.1.tar.gz
  • (optional) to remove the current update archive use sudo rm mediawiki-1.35.2.tar.gz while in the /mw directory or use sudo rm /var/www/mw/mediawiki-1.35.2.tar.gz
2 Likes