How To Install MediaWiki on Ubuntu 24.04 LTS
MediaWiki provides a robust framework for creating and managing wiki-based websites. Its flexibility, extensibility, and active community support make it an excellent choice for organizations, educational institutions, and individuals looking to establish a centralized knowledge base or collaborative platform. Ubuntu 24.04 LTS, with its long-term support and stability, serves as an ideal operating system for hosting MediaWiki.
This guide will cover everything from preparing your Ubuntu system to configuring MediaWiki for optimal performance and security. Whether you’re a system administrator, developer, or enthusiast, you’ll find detailed instructions and helpful tips to ensure a smooth installation process.
Prerequisites
- A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
- An Ubuntu 24.04 system with root access or a user with sudo privileges.
Install MediaWiki on Ubuntu 24.04
Step 1. Updating the Package Repository.
To ensure a smooth installation process, it’s crucial to start with an up-to-date system. Open a terminal and run the following commands:
sudo apt update sudo apt upgrade
This will fetch the latest package information and upgrade any outdated packages to their newest versions.
Step 2. Installing the LAMP Stack.
MediaWiki requires a web server, a database, and PHP to function properly. We’ll install the LAMP (Linux, Apache, MySQL, PHP) stack, which is a popular combination of software for hosting web applications.
Apache is one of the most widely used web servers. To install it, run:
sudo apt install apache2
After installation, start and enable the Apache service:
sudo systemctl start apache2 sudo systemctl enable apache2
Verify that Apache is running by opening a web browser and navigating to your server’s IP address or domain name. You should see the default Apache welcome page.
Installing MySQL Database Server:
sudo apt install mysql-server
Once installed, secure your MySQL installation by running the security script:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, and remove the test database.
MediaWiki requires PHP and several PHP modules. Install them using this command:
sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-intl php-gd php-curl -y
After installation, restart Apache to ensure it recognizes the new PHP modules:
sudo systemctl restart apache2
Step 3. Configuring MySQL for MediaWiki.
Now that we have MySQL installed, let’s create a database and user for MediaWiki:
sudo mysql -u root -p
Create a new database for MediaWiki:
CREATE DATABASE mediawiki;
Create a new user and grant privileges:
CREATE USER 'mediawikiuser'@'localhost' IDENTIFIED BY 'your_strong_password'; GRANT ALL PRIVILEGES ON mediawiki.* TO 'mediawikiuser'@'localhost'; FLUSH PRIVILEGES;
Exit MySQL:
EXIT;
Step 4. Installing MediaWiki on Ubuntu.
Now, let’s download the latest stable version of MediaWiki:
wget https://releases.wikimedia.org/mediawiki/1.42/mediawiki-1.42.1.tar.gz
Extract the downloaded archive:
sudo tar -xvzf mediawiki-1.42.1.tar.gz -C /var/www/html/
Rename the extracted directory for easier access:
sudo mv /var/www/html/mediawiki-1.42.1 /var/www/html/mediawiki
Step 5. Configuring Apache for MediaWiki.
Create a new Apache configuration file for MediaWiki:
sudo nano /etc/apache2/sites-available/mediawiki.conf
Add the following content to the file:
<VirtualHost *:80> ServerName your_domain_or_ip DocumentRoot /var/www/html/mediawiki <Directory /var/www/html/mediawiki/> Options FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/mediawiki_error.log CustomLog ${APACHE_LOG_DIR}/mediawiki_access.log combined </VirtualHost>
Enable the new configuration and disable the default one:
sudo a2ensite mediawiki.conf sudo a2dissite 000-default.conf
Enable the rewrite module and restart Apache:
sudo a2enmod rewrite sudo systemctl restart apache2
Step 6. Securing MediaWiki.
For enhanced security, it’s recommended to use HTTPS. Install Certbot to obtain a free SSL certificate:
sudo apt install certbot python3-certbot-apache sudo certbot --apache -d your_domain_or_ip
Follow the prompts to configure HTTPS for your MediaWiki site.
Step 7. Setting up a Firewall.
Enable the UFW firewall and allow the necessary ports:
sudo ufw enable sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw allow 22/tcp
Step 8. Running the MediaWiki Installation Script.
Open a web browser and navigate to https://your_domain_or_ip/mediawiki
. You should see the MediaWiki installation page. Follow these steps:
-
- Choose your preferred language and click “Continue.”
- On the “Welcome to MediaWiki!” page, click “Continue.”
- The environment check should pass. If there are any issues, resolve them before continuing.
- In the “Connect to database” section:
- Database type: MySQL
- Database host: localhost
- Database name: mediawiki
- Database username: mediawikiuser
- Database password: (the password you set earlier)
- Choose “UTF-8” as the database character set.
- Set up your wiki name and admin account.
- Choose the license for your wiki content.
- Complete the installation process.
After installation, you’ll be prompted to download a file called LocalSettings.php
. Save this file to your local computer.
Congratulations! You have successfully installed MediaWiki. Thanks for using this tutorial for installing MediaWiki on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the MediaWiki website.