MediaWiki is a popular open source wiki platform that can be used for public or internal collaborative content publishing. Originally designed in 2002 to render Wikipedia, MediaWiki is a proven, efficient, and powerful wiki platform.
In this guide, we will be setting up the latest version of MediaWiki on an Ubuntu 14.04 server. We will be using the Lighttpd web server to serve our content, PHP-FPM to handle dynamic processing, and MySQL to store our wiki’s data.
When you have finished with this tutorial, you will have a fully functional, lightweight, wiki. With your new wiki you will be able to collaborate and share any information you desire.
To complete this guide, you will need access to a fresh Ubuntu 14.04 server. For security reasons, you should have a non-root user with sudo privileges for administrative tasks.
Once you have your server set up, log in to your server with your user account and follow the rest of this guide below.
Step 1 — Update System
Now that you have a fresh system image, it is a good idea to go ahead and update your system to the latest packages. You can do this by entering the following commands:
sudo apt-get update
sudo apt-get dist-upgrade
The first command will update your package index files and the second will intelligently upgrade all of your packages to the latest versions in the repositories.
Once you have upgraded all your packages, it is not required, but it is probably a good idea to reboot your system. This way if your kernel or some other packages that could not be restarted were upgraded you will be starting with a clean boot. An easy way to reboot your system is to use the reboot command.
Once your system has come back up, go ahead and login and continue with this tutorial.
Step 2 — Install Lighttpd
Lighttpd (pronounced “lighty”) is a lightweight, fully featured, open source, web server that scales excellently.
Since Lighttpd is supported in the standard Ubuntu repositories all you need do is use the following command to install it:
sudo apt-get install lighttpd
This command will install the lighttpd package on your system, as well as any of the Lighttpd package dependencies that are missing.
You can verify that Lighttpd is running on your server by directing your browser to your server’s FQDN or IP address http://your_server_ip/ and you should see something like this:
Step 3 — Install PHP
PHP-FPM (FastCGI Process Manager) is an alternative PHP CGI implementation that is fast, robust and particularly suited for busy sites. PHP-FPM has been bundled with the official PHP distribution since version 5.3.3.
As php5-fpm is in the Ubuntu repositories, you can install the package with the command:
sudo apt-get install php5-cgi php5-fpm php5-mysql
This will install the php5-fpm package and all required dependencies, such as php5. We also need the php5-mysql package so MediaWiki can interface with our database.
Note: Initially I was stumped when I was unable to get Lighttpd to work with php5-fpm. It seems that on Ubuntu the php5-cgi package is also required to use lighttpd with php5-fpm. The clue lied in the following comment in the /etc/lighttpd/conf-enabled/15-fastcgi-php.conf file:
## Start an FastCGI server for php (needs the php5-cgi package)
Step 4 — Install MySQL
MySQL is a popular open source SQL database implementation. MediaWiki requires a database in which to store our information. The reader might also wish to explore MariaDB and PostgreSQL which are popular alternatives to MySQL.
Enter the following command to install MySQL:
sudo apt-get install mysql-server
This will install the MySQL server and required dependencies. In the process of installing MySQL you will be prompted to enter a password for the MySQL root user.
For security purposes, you will want to enter a unique, strong password and save it in a secure place. It is inadvisable to reuse your system root or sudo user’s password.
You can verify that MySQL installed OK by connecting to your MySQL server with the command:
mysql -u root -p
You will be prompted for the MySQL root password that you entered in the previous step. Enter that password and you will connect to the MySQL server. At the prompt you can enter the command status to get some information about your MySQL server. You can enter the command quit to get back to the shell prompt.
An optional, but recommended step is to run the mysql_secure_installation script. This script will improve your MySQL security. You should be fine accepting the default answers. For more information see the mysql-secure-installation documentation.
To run the script enter this command at your shell prompt:
and follow the prompts.
Step 5 — Install MediaWiki
The newer versions of Ubuntu no longer offer MediaWiki in their repositories. Ubuntu 14.04 repositories contain a version of MediaWiki that is no longer supported. As such, we will be downloading the MediaWiki tarball directly from their site. You can find the download URL for the latest version by visiting https://www.mediawiki.org/wiki/Download in your browser.
As of the writing of this article the latest MediaWiki is version 1.26.3 and the following command will download this version:
curl -O https://releases.wikimedia.org/mediawiki/1.26/mediawiki-1.26.3.tar.gz
Now that you have the MediaWiki tarball you need to extract it and move it into the Lighttpd document directory using the following commands:
tar xvf mediawiki-*.tar.gz
sudo mv mediawiki-*/* /var/www
Once this step is complete, you will have all the packages you need for MediaWiki installed. Now it is time to configure the system.
Step 6 — Enable FastCGI in Lighttpd
In order to use FastCGI we must first enable it in Lighttpd utilizing the following commands:
sudo lighty-enable-mod fastcgi fastcgi-php
sudo service lighttpd restart
Once you have completed this step, you may connect to your wiki to verify that everything is working up to this point. You can do this by pointing your browser to http://your_server_ip/ and you should see something like this:
Step 7 — Set up the Wiki
We have finally reached the point where it is time to set up your wiki! You can either continue by clicking the “set up the wiki” link from the previous step or by pointing your browser to
- Select Your language:
- and your Wiki language:
- and press Continue to move to the next step.
You will now be brought to a screen that does various sanity checks on your environment to make sure everything is OK.
- Click the Continue button to move to the next step.
The next page is where we will be setting up our database information.
- If you followed this tutorial the only Database type: should be MySQL and it should be selected.
- The Database host: should be localhost and you should leave it at that.
- The Database name: defaults to my_wiki and you can change it if you like.
- If you want to have multiple wikis on your server, then you should enter a Database table prefix: otherwise just leave it empty.
- Database username: should default to root and should be left as root.
- Database password: is the password you entered in step 4 of this guide. Enter it now.
- Once you have finished filling out this page, click Continue to move to the next step.
Most users will wish to leave these settings at their defaults.
- Click Continue
to move on to the next page.
- On the next page fill in Name of wiki: to give your wiki a name.
- You will need an Administrator account for your wiki. Enter a username under Your username:.
- You will also need a password for this account. Enter your new account’s password under Password:
- and again under Password again:.
- It is probably a good idea to enter an email address you have access to under the Email address: field. This way if you lose your password you will be able to request a reset.
- Select the I’m bored already, just install the wiki. radial, if you want to answer more questions you are on your own.
- Then click the Continue button to continue.
We are almost there! Now we are on the installation page.
- Click Continue and MediaWiki will continue the install:
- Once the install process is finished, click Continue.
You should now get a page showing that the installation process is complete!
But unless you want to repeat this process again, we have one more step.
Step 8 — Upload Completed Configuration File
As you can see from the page, a file named LocalSettings.php should have been automatically downloaded to your local system. Using whatever method you like, transfer this file to your server.
Once you have copied your LocalSettings.php file onto your server, you will need to move or copy it to your Lighttpd document directory of /var/www/. e.g. if you copied your file to your non-root users directory, and you are currently in that directory the shell command would be:
sudo cp LocalSettings.php /var/www/
Once you have copied your LocalSettings.php file to your /var/www/ directory then you can enter your new wiki by opening http://your_server_ip/ in your browser.
You now have your very own MediaWiki installation that you can use for any purpose you like. Utilizing MediaWiki, Lighttpd, and FastCGI ensures that your wiki will perform well, even on small VPSs. This setup will also scale excellently if you require more resources.