MediaWiki is a free and open-source wiki software that powers many popular websites, including Wikipedia. This guide will walk you through installing MediaWiki on Ubuntu 22.04. Whether you are hosting it locally or on a Windows VPS UK, MediaWiki provides a flexible platform for collaborative content creation.
Step 1: Update Your System
Before installing MediaWiki, it’s important to ensure your system is up to date. Run the following commands to update your package lists and upgrade any existing packages:
sudo apt update && sudo apt upgrade -y
Keeping your system up to date is essential, especially when running applications on servers like VPS Windows Servers.
Step 2: Install Apache, MySQL, and PHP
MediaWiki requires a web server, a database, and PHP to function. Install Apache, MySQL, and PHP along with the required PHP modules:
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql php-xml php-intl php-mbstring -y
Start and enable Apache and MySQL:
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mysql
sudo systemctl enable mysql
Step 3: Create a MySQL Database for MediaWiki
Log in to the MySQL shell to create a database and user for MediaWiki:
sudo mysql -u root -p
In the MySQL shell, run the following commands:
CREATE DATABASE mediawiki_db;
CREATE USER 'mediawiki_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON mediawiki_db.* TO 'mediawiki_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace your_password
with a strong password of your choice.
Step 4: Download and Install MediaWiki
Download the latest version of MediaWiki from the official website. Navigate to the Apache web root directory and download MediaWiki:
cd /var/www/html
sudo wget https://releases.wikimedia.org/mediawiki/1.37/mediawiki-1.37.1.tar.gz
Extract the downloaded archive:
sudo tar -xvzf mediawiki-1.37.1.tar.gz
sudo mv mediawiki-1.37.1 mediawiki
Set the correct permissions for the MediaWiki directory:
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
Create a new Apache virtual host configuration file for MediaWiki:
sudo nano /etc/apache2/sites-available/mediawiki.conf
Add the following configuration:
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html/mediawiki
ServerName yourdomain.com
ServerAlias www.yourdomain.com
<Directory /var/www/html/mediawiki/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file. Then, enable the MediaWiki site and the Apache rewrite module:
sudo a2ensite mediawiki.conf
sudo a2enmod rewrite
sudo systemctl reload apache2
Step 6: Complete MediaWiki Installation
Open your web browser and navigate to http://yourdomain.com/mediawiki
to access the MediaWiki installation page. Follow the on-screen instructions to configure the database, admin account, and other settings.
Step 7: Secure MediaWiki with Let's Encrypt SSL (Optional)
To secure your MediaWiki site with HTTPS, you can obtain a free SSL certificate from Let's Encrypt. First, install Certbot:
sudo apt install certbot python3-certbot-apache -y
Next, run Certbot to obtain and install the SSL certificate:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Follow the prompts to set up SSL. Certbot will automatically configure your virtual host file to use the SSL certificate.