How to Install MediaWiki on a Ubuntu

Key Takeaways

For those in a hurry, here’s the quick overview of installing MediaWiki on Ubuntu:

  • Install the LAMP Stack: Update your server and install the core components: Apache, MySQL, and PHP, along with necessary PHP modules.
  • Create a Database: Secure your MySQL installation and create a dedicated database and user for MediaWiki.
  • Download & Prepare: Download the latest MediaWiki stable release, extract it to a web-accessible directory (e.g., /var/www/html/wiki), and set the correct file permissions.
  • Run the Web Installer: Access the installation directory via your web browser to run the graphical installer, which configures the database connection.
  • Secure & Configure: Move the generated LocalSettings.php file to the root of your wiki directory and set its permissions to chmod 600 to secure it.

What Are the Prerequisites for Installing MediaWiki?

Before you begin, you must have a running instance of Ubuntu Server (this guide assumes 20.04 or later). You also need SSH access with a user account that has sudo (administrative) privileges.

This installation guide focuses on the “LAMP” stack, which stands for:

  • Linux (your Ubuntu OS)
  • Apache (your web server)
  • MySQL (your database server)
  • PHP (the scripting language MediaWiki runs on)

If you have these components already, you can skip to the relevant sections.

How Do I Install the LAMP Stack Components?

This section walks you through setting up the complete web server environment from scratch.

Install MediaWiki

How to Install MediaWiki on Ubuntu: A Detailed Procedure

MediaWiki is a free and open-source software that powers Wikipedia and many other websites. This guide provides a step-by-step procedure for installing MediaWiki on an Ubuntu server. The guide assumes that you have a basic understanding of Linux commands and have sudo privileges on the server.

Install MediaWiki Pre-requisites

  1. Ubuntu Server: A running instance of Ubuntu (18.04 or later is recommended).
  2. SSH Access: Secure Shell (SSH) access to your Ubuntu server.
  3. LAMP Stack: Linux, Apache, MySQL, and PHP installed on your server.

Step 1: Update Ubuntu Packages

Firstly, update the package list and upgrade the installed packages to their latest versions.

Bash
sudo apt update -y
sudo apt upgrade -y  #You can optionally upgrade the OS

Step 2: Install Apache Web Server

If Apache is not already installed, you can install it using the following command:

Bash
sudo apt install apache2 -y

Step 3: Install MySQL Database Server

Install MySQL by executing the following command:

Bash
sudo apt install mysql-server -y

Step 4: Secure MySQL Installation

Run the MySQL security script to secure your database.

Bash
sudo mysql_secure_installation

Follow the prompts to set a root password and secure your MySQL installation.

Step 5: Install PHP

MediaWiki requires PHP to function. Install PHP and some additional modules with the following command:

Bash
sudo apt install php php-mysql php-xml php-mbstring -y

How Do I Install MediaWiki?

With the server stack ready, you can now download and configure the MediaWiki software itself.

Step 6: Download and Install MediaWiki

It’s best practice to install MediaWiki in its own directory, rather than the web root. We’ll use /var/www/html/wiki.

First, navigate to the html directory and use wget to download the latest stable release. You can find the URL for the latest .tar.gz file from the official MediaWiki Download page.

Bash
cd /var/www/html 
wget https://releases.wikimedia.org/mediawiki/1.42/mediawiki-1.42.0-rc.0.tar.gz

Step 7: Extract MediaWiki Archive

Before the web installer can run, the Apache web server (which runs as the www-data user on Ubuntu) needs permission to write files to your wiki directory.

Run the following command to grant ownership of the wiki directory to the www-data user:

sudo chown -R www-data:www-data /var/www/html/wiki

Failure to do this will result in “permission denied” errors during the web-based setup.

Extract the downloaded tarball and move the contents to a new directory.

Bash
tar xzvf mediawiki-*.tar.gz mv mediawiki-1.42.0-rc.0/* /var/www/html/

Step 8: Create a MySQL Database

Log in to MySQL and create a new database for MediaWiki.

Bash
mysql -u root -p 
CREATE DATABASE mediawiki; 
GRANT ALL PRIVILEGES ON mediawiki.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'mysuperstrongpassword'; 
FLUSH PRIVILEGES; 
EXIT;

Step 9: Run Install MediaWiki Script

Open a web browser and navigate to http://your_server_ip/. Follow the on-screen instructions to complete the MediaWiki installation.

Step 10: Configure Apache

Finally, configure your Apache server to serve the MediaWiki site. Edit the Apache configuration file as needed.

Advanced Customization and Integration of MediaWiki on Ubuntu

Once you’ve successfully installed MediaWiki on your Ubuntu server, you may want to explore advanced customization options and integration with other software to enhance its capabilities. This guide will walk you through some of these advanced steps.

Customizing MediaWiki Appearance

Install Themes

  1. Download Theme: Download your desired MediaWiki theme from the MediaWiki Skins directory.
  2. Upload to Server: Upload the theme folder to /var/www/html/skins/ on your server.
  3. Edit LocalSettings.php: Open the LocalSettings.php file and add the following line to activate the theme:

Bash
wfLoadSkin('YourThemeName');

Customize Logo

  1. Upload Logo: Upload your custom logo to /var/www/html/resources/assets/.
  2. Edit LocalSettings.php: Add the following line to change the logo

Bash
$wgLogo = "$wgResourceBasePath/resources/assets/your_logo.png";

Extending MediaWiki Functionality

Install Extensions

  1. Download Extension: Download your desired extension from the MediaWiki Extensions directory.
  2. Upload to Server: Upload the extension folder to /var/www/html/extensions/.
  3. Activate Extension: Open LocalSettings.php and add the following line

Bash
wfLoadExtension('YourExtensionName');

Integration with Other Software

LDAP Integration

  1. Install LDAP Extension: Follow the steps above to install the LDAP Authentication extension.
  2. Configure LDAP: Add the LDAP configuration to your LocalSettings.php file. This will include the LDAP server details and user credentials.

Visual Editor

  1. Install Parsoid: Visual Editor requires Parsoid to run. Install it using:

Bash
sudo apt install parsoid

  1. Configure Parsoid: Edit the Parsoid settings to point it to your MediaWiki API.
  2. Activate Visual Editor: Install and activate the Visual Editor extension as described above.
Elsewhere On TurboGeek:  How to SCP Linux

Backup and Restore

Backup

  1. Backup Database: Use mysqldump to backup your MediaWiki database.

Bash
mysqldump -u root -p mediawiki > mediawiki_backup.sql 

Backup Files: Archive the MediaWiki installation directory.

Bash
tar czvf mediawiki_files_backup.tar.gz /var/www/html/

Restore

Restore Database: Use mysql to restore the database

Bash
mysql -u root -p mediawiki < mediawiki_backup.sql

Restore Files: Extract the archived files back into the MediaWiki installation directory.

Advanced customization and integration can significantly extend the capabilities of your MediaWiki installation. Whether you’re looking to change the appearance, add new features, or integrate with other platforms, these steps offer a solid foundation.

Install MediaWiki: Your Questions Answered

Q: How do I install MediaWiki?

A: Installing MediaWiki involves several steps:

  1. Check System Requirements: Ensure your server meets the minimum requirements (web server, PHP, database).
  2. Download MediaWiki: Get the latest version from the official MediaWiki website.
  3. Set Up Database: Create a database and user for MediaWiki to use.
  4. Upload Files: Transfer the MediaWiki files to your web server.
  5. Run the Installation Script: Access the installation script through your web browser and follow the prompts.

Q: Can I install MediaWiki on my own computer?

A: Yes! You can install MediaWiki locally on your computer for testing or personal use. You’ll need to set up a local web server (like XAMPP or WAMP) and database.

Q: Is there an easy way to install MediaWiki?

A: Many web hosting providers offer one-click installs or automated installers for MediaWiki, simplifying the process. If you’re not comfortable with manual installation, this could be a good option.

Q: What are the best practices for installing MediaWiki?

A: Here are some tips for a successful installation:

  • Keep Software Updated: Use the latest versions of MediaWiki, PHP, and your database software for security and performance.
  • Secure Your Wiki: Set up strong passwords, restrict access where necessary, and consider using HTTPS.
  • Customize Your Wiki: Explore MediaWiki’s many extensions and themes to personalize your wiki’s appearance and functionality.

Q: Where can I find detailed installation instructions?

A: The official MediaWiki website offers comprehensive installation manuals:

Q: What if I get stuck during installation?

A: Don’t worry! There are several resources to help you:

  • MediaWiki Community: Ask for help on the MediaWiki forums or mailing lists.
  • Web Hosting Support: If you’re using a web host, contact their support for assistance.
  • Professional Help: Consider hiring a developer or system administrator to help with the installation.

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »