How to Install MediaWiki with PHP 7 on an Ubuntu 18.04 VPS or Dedicated Server


What is MediaWiki?

MediaWiki is basically a software by wiki which is totally free and open-source. It currently runs on many famous websites such as Wikipedia, Wiktionary and Wikimedia Commons. MediaWiki is written in PHP.

Its function is to store the contents into a database. Assuming you have VPS hosting or dedicated server hosting, let's get started!

The Requirement for MediaWiki 1.30.0

  1. You will require MariaDB 5.1, SQLite 3, MySQL 5.0.2 or PostgreSQL 9.0 or later;
  2. And Apache web server 2.0 or higher compiled with the mod_rewrite module;
  3. And finally, you will need the PHP 5.5.9 or higher, with these extensions enabled: mbstring, JSON, Intl, curl, MySQL and GD PHP

Step 1: Installing Apache server

First things first, on your virtual server you will have to install and configure Apache.

$ sudoapt-get install apache2

Step 2: Server OS packages update

You will have to check if the server OS packages are updated to get started with the installation.

$ sudo apt-get update 
$ sudo apt-get upgrade

Step 3: Package installation

Then you have got to install all the required packages.

$ sudo apt-get install imagemagick php7.0-intl php7.0-curl php7.0-gd php7.0-mbstring php7.0-mysql mysql-server php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0

Step 4: Enabling the Apache rewrite module

You will have to make sure the Apache rewrite module is enabled.

$ sudo a2enmod rewrite

Step 5: Restarting the Apache

Once you have enabled the Apache rewrite module you have got to restart the Apache services.

$ sudo service apache2 restart

Step 6: MediaWiki installation

In this step, you have got visit https://www.mediawiki.org/wiki/download and then download the latest version of MediaWiki available here. Download it to the /opt/ directory on the server.

$ cd /opt/
$ sudo wget https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz
$ sudo tar -xvzf mediawiki-1.31.0.tar.gz
$ sudo mv /opt/mediawiki-1.31.0/ /var/www/html/mediawiki

You will have to set up a proper ownership so that all the files are readable by the server.

$ sudo chown www-data:www-data -R /var/www/html/mediawiki

Then you have got to create a new MySQL database and user.

mysql -u root -p
mysql> SET GLOBAL sql_mode='';
mysql> CREATE DATABASE mediawiki;
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'your-password';
mysql> GRANT ALL PRIVILEGES ON mediawiki.* TO 'newuser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit

The ‘your-password’ next to IDENTIFIED BY is your password. Feel free to change it and type in a password of your choice.

Next, in Apache, you will have to create a new virtual host directive. For instance, on your virtual server, create a new Apache configuration file, say ‘mediawiki.conf’.

$ sudo touch /etc/apache2/sites-available/mediawiki.conf
$ sudo ln -s /etc/apache2/sites-available/mediawiki.conf /etc/apache2/sites-enabled/mediawiki.conf
$ sudo vi /etc/apache2/sites-available/mediawiki.conf

Once you have done this, add the following lines by pressing “i” to insert and press Esc button and type :wq to save and exit the editor.

<VirtualHost *:80>
ServerAdmin admin@your-domain-name.com
DocumentRoot /var/www/html/mediawiki/
ServerName your-domain-name.com
ServerAlias www.your-domain-name.com
<Directory /var/www/html/mediawiki/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/your-domain-name.com-error_log
CustomLog /var/log/apache2/your-domain-name.com-access_log common
</VirtualHost>

Then you have got to remove the file, i.e., OOO-default.conf.

$ sudo rm /etc/apache2/sites-enabled/000-default.conf

Now in order to save the changes and for them to take effect, you have got to restart the Apache web server.

$ sudo service apache2 restart

In any browser of your choice visit http://your-domain-name.com. There you will find the hyperlink saying ‘set up the wiki’. Click on ‘set up the wiki’.

This will take you to the installation screen.

Firstly you will have to select your language and Wiki language. Then clicking on Continue will take you to the next page.

There you will have to enter the following information if all the requirements are met and then click on the ‘Continue’ button.

 How to install MediaWiki in VPS

The next step will require some database configuration. Under “Database type” select MySQL. Then write “localhost” under Database host.

Then you have to go to fill the rest of the information according to the database that you created in the first step of this tutorial. Click on the “Continue” button once you have successfully entered all the correct information.

You will be taken to the next page where you have got to select:

Storage engine: InnoDB

 How to install MediaWiki in VPS

Once you have done this, click on the ‘Continue’ button.

Then you will have to enter the name of Wiki. This name will appear in the title bar of the browser.

Create an administrator account. Once you have done all this, you are all set to install Wiki.

 How to install MediaWiki in VPS

You can add the following lines at the bottom of the LocalSettings.php file if you hate waiting and want to speed up the installation process.

$ sudo vi /var/www/html/mediawiki/LocalSettings.php

# Speed improvements
$wgUseGzip = true;
$wgUseFileCache = true;

# Performance settings
$wgDisableCounters = true;
$wgMiserMode = true;

You will also have to set a proper ownership for the LocalSettings.php configuration file.

$ sudo chown www-data:www-data /var/www/html/mediawiki/LocalSettings.php

This wraps up our installation process by successfully installing MediaWiki on your server.

 How to install MediaWiki in VPS

Finally, you have successfully installed Mediawiki, We hope our article helped you :).

Check out these top 3 VPS services:

Was this article helpful?