MediaWiki is a free and open-source wiki software that is highly customizable and used by many organizations and individuals for knowledge management, including Wikipedia. Installing MediaWiki on a Virtual Private Server (VPS) enables you to host your own knowledge base or wiki system.
In this guide, we’ll walk you through the steps to install and set up MediaWiki on a VPS for efficient knowledge management.
Prerequisites
Before proceeding with the installation, make sure that your VPS meets the following requirements:
- A VPS running Ubuntu 20.04 or later (or any other compatible Linux distribution).
- Root or sudo privileges to execute system commands.
- A domain name (optional) for easier access to the wiki.
- At least 2 GB of RAM and 1 CPU core (recommended).
- Access to the internet to download required packages and dependencies.
Step 1: Update Your VPS
To ensure your server is up to date and secure, start by updating the package lists and upgrading the installed packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
MediaWiki requires a web server, PHP, and a database to store its data. The most commonly used combination is Apache, PHP, and MySQL/MariaDB.
Install Apache Web Server:
Apache is a widely used web server. Install it with the following command:
sudo apt install apache2 -y
Install PHP and Required Extensions:
MediaWiki requires PHP 7.3 or higher along with several extensions. Install PHP and the necessary extensions:
sudo apt install php php-mbstring php-xml php-mysql php-intl php-gd php-curl php-zip php-bz2 php-json -y
Install MySQL or MariaDB:
MediaWiki requires a database to store its data. We’ll install MySQL (MariaDB can also be used, as it’s compatible with MySQL):
sudo apt install mysql-server -y
Secure the MySQL installation by running the following command and following the on-screen instructions:
sudo mysql_secure_installation
Step 3: Create a Database for MediaWiki
Next, we need to create a database that MediaWiki will use.
-
Log into MySQL:
sudo mysql -u root -p
-
Create the MediaWiki database:
sqlCREATE DATABASE mediawiki;
-
Create a user for MediaWiki:
sqlCREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'strongpassword';
-
Grant privileges to the user:
sqlGRANT ALL PRIVILEGES ON mediawiki.* TO 'wikiuser'@'localhost';
-
Flush privileges and exit MySQL:
sqlFLUSH PRIVILEGES; EXIT;
Step 4: Download and Install MediaWiki
Now that we’ve installed the required dependencies and created the database, let’s install MediaWiki.
-
Download the latest MediaWiki release:
Go to the MediaWiki download page and copy the latest stable release link. Use
wget
to download it:wget https://releases.wikimedia.org/mediawiki/1.39/mediawiki-1.39.0.tar.gz
-
Extract the MediaWiki archive:
tar -xvzf mediawiki-1.39.0.tar.gz
-
Move the extracted files to the Apache web root:
sudo mv mediawiki-1.39.0 /var/www/html/mediawiki
-
Set the correct permissions:
sudo chown -R www-data:www-data /var/www/html/mediawiki sudo chmod -R 755 /var/www/html/mediawiki
Step 5: Configure Apache for MediaWiki
To make MediaWiki accessible via the web, you need to configure Apache.
-
Create a new Apache configuration file for MediaWiki:
sudo nano /etc/apache2/sites-available/mediawiki.conf
-
Add the following content to the configuration file:
apache<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/mediawiki ServerName yourdomain.com <Directory /var/www/html/mediawiki> AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
-
Enable the new site and necessary Apache modules:
sudo a2ensite mediawiki.conf sudo a2enmod rewrite sudo systemctl restart apache2
Step 6: Complete the MediaWiki Installation via Web Interface
-
Open your browser and navigate to your server’s IP address or domain name:
arduinohttp://yourdomain.com
You will be greeted by the MediaWiki installation page. If you’re using a domain, replace
yourdomain.com
with your actual domain name. -
Choose your language and click Continue.
-
Check PHP configuration: MediaWiki will verify your PHP setup and database configuration. Ensure all required extensions are installed and enabled. If everything is fine, click Continue.
-
Configure the Database: Enter the following details:
- Database type: MySQL
- Database host:
localhost
- Database name:
mediawiki
- Database user:
wikiuser
- Database password:
strongpassword
(use the password you created earlier)
Click Continue.
-
Configure Wiki Settings: You will now need to set up basic wiki information such as:
- Wiki name (e.g., "My Knowledge Base")
- Administrator username, password, and email
-
Generate the LocalSettings.php file: Once the installation is complete, MediaWiki will generate a
LocalSettings.php
file. Download this file and upload it to themediawiki
directory:sudo mv ~/Downloads/LocalSettings.php /var/www/html/mediawiki
Step 7: Finalize the Installation
-
Set proper permissions for the
LocalSettings.php
file:sudo chown www-data:www-data /var/www/html/mediawiki/LocalSettings.php sudo chmod 644 /var/www/html/mediawiki/LocalSettings.php
-
Restart Apache to apply any changes:
sudo systemctl restart apache2
Step 8: Access Your MediaWiki Wiki
Your MediaWiki installation is now complete. You can access your wiki by navigating to your server’s IP address or domain in a web browser:
http://yourdomain.com
Log in using the administrator credentials you created during the installation process. You can start creating articles, managing users, and configuring your wiki settings from the web interface.
Step 9: Secure Your MediaWiki Installation (Optional but Recommended)
For better security, you should:
-
Set up SSL (HTTPS): Secure your MediaWiki installation by using Let's Encrypt or any other SSL certificate provider.
Example using Let’s Encrypt (Certbot):
sudo apt install certbot python3-certbot-apache -y sudo certbot --apache
-
Regular Backups: Regularly back up your database and MediaWiki files to avoid data loss.
-
Monitor MediaWiki: Use monitoring tools like UptimeRobot or Prometheus to monitor the health of your VPS and wiki.
Conclusion
You’ve successfully installed and configured MediaWiki on your VPS for knowledge management. Now you can use it to create, organize, and manage your knowledge base. Whether you're using it for internal documentation, project management, or community-driven content, MediaWiki provides a powerful, flexible platform to help you manage information efficiently.
If needed, you can further customize your wiki by installing extensions, themes, and other tools to enhance its functionality.