MediaWiki is a free and open-source software that powers Wikipedia and many other wiki websites. It allows you to create and edit web pages collaboratively using a simple markup language.
In this tutorial, we will show you how to install MediaWiki on Ubuntu, a popular Debian based Linux distribution for servers.
If you're looking for MediaWiki installation tutorial on CentOS or similar distribution, check out this article on Installing MediaWiki on CentOS.
Prerequisites
Before you start, you will need the following:
- An Ubuntu server with root access or sudo privileges
- A domain name or an IP address that points to your server
- A web browser to access the MediaWiki installation wizard
Step 1: Install required packages
The first step is to install (Apache) web server, (MariaDB) database server and PHP language interpreter that MediaWiki requires.
- To install all packages, run the following commands as root or with sudo:
sudo apt update
sudo apt install apache2 mariadb-server php php-mysql php-xml php-curl php-dom
This will install the latest versions of these packages from default apt repositories of Ubuntu.
- Start and enable Apache and MariaDB daemon using:
sudo systemctl enable --now httpd
sudo systemctl enable --now mariadb
You can check the status of these services with the below command:
sudo systemctl status httpd
sudo systemctl status mariadb
All green! We are ready to move forward to the next step now.
The next step is to secure MariaDB and create a database and a user for MediaWiki.
sudo mysql_secure_installation
This prompts to set a secure root password for MariaDB, remove anonymous users, disable remote root login, remove the test database and reload the privilege tables. You can answer with y
or Y
to all these questions for better security, or customize them according to your preferences.
After securing MariaDB, you can log in to the MySQL shell as root with the following command:
mysql -u root -p
Enter the root password that you set earlier.
Now, you can create a database for MediaWiki with the following command:
CREATE DATABASE wikidb;
You should see similar output as given below:
Query OK, 1 row affected (0.00 sec)
Next, you can create a user for MediaWiki and grant it all privileges on the wikidb
database with the following command:
GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';
Replace wikiuser
and password
with your desired username and password for MediaWiki.
You should see something starting with QUERY OK
on console.
Finally, you can flush the privileges and exit the MySQL shell with the following commands:
FLUSH PRIVILEGES;
EXIT;
Query OK, 0 rows affected (0.00 sec)
Bye
Great! You have created database and user for MediaWiki and set proper authorizations.
The next step is to download and extract the latest version of MediaWiki from its official website. To do this, run the following commands as root or with sudo:
cd /tmp
wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.tar.gz
tar xvfz mediawiki-1.35.2.tar.gz -C /var/www/html/
mv /var/www/html/mediawiki-1.35.2/* /var/www/html
rm /var/www/html/mediawiki-1.35.2/ -rf
This will download the MediaWiki archive file to the /tmp
directory, extract it to the /var/www/html
directory, move its contents to the web root directory and delete the empty mediawiki-1.35.2
directory.
The next step is to change the ownership and permissions of the MediaWiki files so that Apache can access them properly.
Run the following commands as root or with sudo:
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
This will change the owner and group of all files and directories under /var/www/html
to Apache, and set the permissions to 755 (read, write and execute for owner, read and execute for group and others).
The final step is to run the MediaWiki installation wizard from your web browser.
Open your web browser and navigate to “http://yourserverip/” or “http://localhost/” (replace with your actual IP address or domain name).
Click on “Set up the wiki” to start the installation process.
Follow the on-screen instructions to complete the installation. You will need to provide some basic information, such as:
- name of your wiki
- language of your wiki
- project namespace of your wiki
- admin username and password for your wiki
- database name, user, and password that you created earlier
You can also customize some advanced settings such as:
- The email settings for your wiki
- The license of your wiki content
- The extensions that you want to enable for your wiki
After completing all the steps, click on “Continue” to go to your wiki homepage.
Awesome! You have successfully installed MediaWiki on your server! Thank you for reading!