Install MediaWiki with Lighttpd on Ubuntu 14.04

Written on May 25, 2016

MediaWiki is a popular wiki application, which caters to collaborative content publishing projects like Wikipedia.

In this guide we will discuss how to install MediaWiki on a Lighttpd web server with PHP5-FPM. The Lighttpd application is a lighter alternative to Apache. PHP modules like PHP5-FPM help manage dynamic processing. Combining the two provides a robust and light web server for your private wiki.

Prerequisites

To complete this guide, you should have access to a clean Ubuntu 14.04 server instance. On this system, you should have a non-root user configured with sudo privileges for administrative tasks. You can learn how to set this up by following our Ubuntu 14.04 initial server setup guide.

When you are ready to continue, log into your server with your sudo user and get started below.

Step 1 – Install the Server Components

MediaWiki needs basic resources before it can serve content to the user.

First we will need to install a web server. In this tutorial, we’ll install Lighttpd from the default Ubuntu repositories.

To do this we need to update our local package index with apt.

sudo apt-get update

Use apt to install the program.

sudo apt-get install lighttpd

Your web server should be serving the default page for Lighttpd.

By visiting your server’s public IP address, you can verify that Lighttpd works.

http://your_server_IP_address

Now you can retrieve your server’s IP address.

ifconfig eth0 | grep inet | awk '{print $2}'

You should see the default placeholder page.

You should see the default placeholder page. If you see this, your web server is correctly installed.

Step 2 – Configure MySQL and Create Credentials for MediaWiki

Now that we have a working web server, we need to install MySQL, a database management system, to store and manage the data for our site.

Install this by using the apt-get.

sudo apt-get install mysql-server

During the installation, your server will ask you to select and confirm a password for the MySQL root user. This is an administrative account in MySQL with higher privileges. Think of it as being like the root account for the server itself. Use a secure password and do not reuse it.

When the installation is complete, we need to run some additional commands to secure the MySQL environment.

Execute this command to initialize the MySQL data directory.

sudo mysql_install_db

Run a simple security script to protect the database with the following command. The script will ask to enter the password you set for the MySQL root account. Type in your credentials.

sudo mysql_secure_installation

Next you are given a series of prompts. The first is to change your root password.

Because there may be no significant security benefit, you may not want to change your root password here. Type N for no here.

we should accept all other security options. For each prompt, hit the ENTER key.

We are ready to make the actual database.

Log into your MySQL.

mysql -u root -p

Create the wiki database that is used for the wiki site.

create database wikidb;

It’s never safe to run any application under your root account, especially for your MySQL database. Make a new user for your database.

grant index, create, select, insert, update, delete, drop, alter, lock tables on wikidb.* to 'wikiuser'@'localhost' identified by 'password';

Reload the privileges in the MySQL database.

flush privileges;

Exit the MySQL database.

exit;

You created a MySQL database structure, which you will recall later in this tutorial.

Step 3 – Configure PHP5-FPM and Lighttpd

After the database and server are setup, we need to install some essential PHP. In this case, we will install PHP5-FPM. FPM is necessary for Lighttpd to process dynamic webpages and multiple inquires at once.

To install FPM we use apt-get.

sudo apt-get install php5-fpm php5

Now that the files are installed, we should enable them.

To enable PHP5 in Lighttpd, we modify /etc/php5/fpm/php.ini and uncomment the line cgi.fix_pathinfo=1.

Use the nano application on your Ubuntu server to open the file /etc/php5/fpm/php.ini.

sudo nano /etc/php5/fpm/php.ini

With nano you can search for this code with CRTL + W. Enter ; cgi.fix_path to locate the line. Remove the semicolon to uncomment it.

Your new configuration file should look like this:

. . .
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=1
. . .

You can close the file and save it.

Restart PHP-FPM.

sudo restart php5-fpm

By default Lighttpd uses FastCGI, but we want to use FPM. You will need to configure the FastCGI file to do so.

Open the file with nano.

sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf

Next we are configuring the FastCGI to listen for FPM.

Remove what you have in this file and replace it with the contents below.

# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/Lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "socket" => "/var/run/php5-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)

Enable the FastCGI configuration.

sudo lighttpd-enable-mod fastcgi
sudo lighttpd-enable-mod fastcgi-php

Then we reload Lighttpd.

sudo service lighttpd force-reload

Your webpage inquiries are now handled by FPM.

Getting MySQL Support In PHP5

Once we’re done configuring FPM, we will need to connect MySQL to PHP.

Therefore our next step is to install another package from apt-get. This will be the basis of how you can install other PHP packages in the future.

Install a php5-mysql package to implement PHP with our MySQL database.

sudo apt-get install php5-mysql

Next we can install the packages php5-xcache and php5-intl to improve the overall performance of our wiki. The php5-cli package will allow us to upgrade our wiki in the future.

sudo apt-get install php5-xcache php5-intl php5-cli

Restart FPM to implement the new packages.

sudo restart php5-fpm

Now your server supports MySQL with FPM.

You may repeat this step to install new PHP packages in the future.

Step 4 – Install MediaWiki

After we’ve installed the server, your web server can support MediaWiki. We will install the latest version.

In this case, we cannot use apt-get. To use the most recent version of MediaWiki we must download it elsewhere.

We use wget to download the compressed tar file.

wget https://releases.wikimedia.org/mediawiki/1.26/mediawiki-1.26.2.tar.gz

Extract the MediaWiki files from the compressed file which creates a directory named mediawiki-1.25.2.

tar xvzf mediawiki-*.tar.gz

Move the folder to your web directory.

sudo mv -v mediawiki-1.26.2/ /var/www/

Move the MediaWiki files to the wiki directory. This will create a new wiki directory. The new path makes it easier to access.

sudo mv /var/www/mediawiki-1.26.2 /var/www/wiki

You can navigate to your wiki using a browser.

http://your_server_IP_address/wiki

You should see MediaWiki and its version number.

Configuring Your LocalSettings.php File

Once you have navigated to your web server, you should see a page alerting you that your LocalSettings.php was not found. In order to use your wiki application, you will need this PHP file on your web server. MediaWiki fortunately has an guide to help you with this process.

MediaWiki cannot find your LocalSettings.php.

First you should click on the “set up the wiki” link. This will start a web application that will help you create the LocalSettings.php. Click on the continue button at the bottom of each page to go to the next step.

Choose the your default language.

Next we choose the MySQL database we created.

Type in your host, which should be localhost.

Type in the your username and password.

Since we made a database structure already, we’re going to use those credentials.

Do not use your `root` credentials here. If we use our `root` password here, we won't use the database we created. Using `root` makes our system less secure.

Once we select our database, we must configure it. We are going to use the default configuration. You can hit the continue button at this step. InnoDB and Binary should be selected.

InnoDB and Binary should be selected.

Next we need to setup the wiki.

We are defining a name, username, privacy, and a few miscellaneous options.

After you select a name for your wiki and username, highlight “Ask me more questions” radio button. Click the continue button.

Highlight "Ask me more questions" radio button

On the next page we select a privacy level.

After picking your privacy, you will need to pick a license.

Depending on your needs, you may need a different license. If you simply want your wiki to work, you may be better off with a Creative Commons license. Everything else can be left alone.

Then we need to change the caching.

Because we installed XCache, we can enable PHP object caching.

Highlight the “PHP object caching” radio button.

Click on PHP object caching.

After you click continue, we should be ready to install the LocalSettings.php file.

Downloading and Installing the LocalSettings.php File

Now that you configured your LocalSettings.php file. It’s time to download it to your desktop computer. We’re going to put it on your web server later.

Click on download link to receive file.

To download the file, we simply click on the link above. Your browser will put the file in the appropriate folder.

We can upload the file using SFTP or PSCP.

Do not share `LocalSettings.php` or upload it elsewhere. It stores your database password in clear text. This is why we didn't use our `root` password. If you did use your `root` password, go back and create a new database and use that instead.

On Linux or Mac, you can upload the file with your SSH client using SFTP.

sftp username@your_server_IP_address
put /home/user/Downloads/LocalSettings.php

On Windows, you will need to send the file through PuTTY.

Download PuTTY and PSCP.

Open cmd.

Enter this.

pscp source_file_name username@your_server_IP_address:/home/user/

Finally, log into your web server using an SSH client.

Move your file to your web server.

sudo mv LocalSettings.php /var/www/wiki/

After you moved these files over to your web server, you should be able to click on “enter your wiki” link.

You should see the main page..

The wiki application should open to the main page.

Conclusion

You should now have the latest version of MediaWiki installed on your Ubuntu 14.04 Lighttpd web server. You should now be able to enter in your server’s IP address to visit the page.

This version doesn’t update itself when you type any command in apt-get.

Whenever you wish to update MediaWiki, use this script.

php /var/www/wiki/maintenance/update.php

That’s all you should need for the base system. You may now explore your installation of MediaWiki and customize it.


Take me home.

Check out the archive.