Skip to content

Instantly share code, notes, and snippets.

@jacqueline-homan
Created May 11, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqueline-homan/3c16eda7c5308446597f74a34e4bdf93 to your computer and use it in GitHub Desktop.
Save jacqueline-homan/3c16eda7c5308446597f74a34e4bdf93 to your computer and use it in GitHub Desktop.
Lighttpd Web Server Setup on Ubuntu 14.04 - LTS
# Setting Up MediaWiki With the Lighttpd Web Server on Ubuntu 14.04 #
## by Jacqueline S. Homan ##
**MediaWiki** is a popular Wiki framework. It is a "webapp," meaning that instead of being installed like a traditional program, a tarball (or compressed/gzipped file) of scripts and PHP code is downloaded and decompressed into the document root (usually /var/www/http/, in our case /var/www/) of the server. The web server, usually Apache, can then serve the wiki up to other machines which access it over port 80 and the correct URL.
In this article, we will be installing the latest MediaWiki onto an Ubuntu 14.04.4 "Trusty Tahr" LTS host, using Lighttpd as our web server rather than Apache. The steps documented here will work on both a locally-installed copy of Ubuntu and on a remotely-hosted VPS such as Linode or Digital Ocean.
MediaWiki requires an SQL database backend and a PHP interpreter in order to work. We will be setting up what is known as a "LLMP stack" (Linux, Lighttpd, MySQL/MariaDB, PHP), where Lighttpd substitutes for Apache in the original "LAMP stack."
Additionally, while Ubuntu's repositories do offer a MediaWiki package, it is rather outdated. So we will be using `wget` or `curl` to download the latest release.
### Prerequisites:
- Ubuntu 14.04.4 OS, preferably amd64 arch
- MySQL (or MariaDB) SQL server
- PHP 5 packages
- Lighttpd web server
- cURL or wget
### Procedure: ###
This tutorial assumes that you have already installed and configured Ubuntu 14.04.4, and that you have either root access or sufficient privileges via `sudo`. If not, contact your system administrator first.
### Step 1: Lighttpd
Open a terminal and run the command `sudo apt-get install lighttpd`. Ubuntu will notify you of extra packages and suggest others. It is safe to simply approve of the requested actions. You may add the -y switch to the apt-get command to skip this check.
![mediawiki1](https://cloud.githubusercontent.com/assets/3537889/14404230/d27e824e-fe3e-11e5-9e9a-33e8842e03b7.jpg)
The Lighttpd service will be started automatically. To restart (or stop, start, etc) the service, run the following command in your terminal: `sudo service lighttpd restart` (or stop, start, etc).
Verify that Lighttpd is working by pointing a web browser to your server's WAN-facing IP, or 127.0.0.1 if you're doing this locally.
![mediawiki2](https://cloud.githubusercontent.com/assets/3537889/14404242/036362d0-fe3f-11e5-8b40-9505d77bf9ee.jpg)
Lighttpd's configuration file resides at /etc/lighttpd/lighttpd.conf and files created by the daemon have the user- and groupname
www-data. The document root, which may be changed in the config file, defaults to /var/www/.
### Step 2: MySQL
Next, run the command `sudo apt-get install mysql-client mysql-server`
![mediawiki3](https://cloud.githubusercontent.com/assets/3537889/14404304/5bbaa3ac-fe40-11e5-8a56-467b5c30d666.jpg)
When prompted, enter a root password for the MySQL server. It is strongly advised that you **do not** reuse your Linux account password or, if present, the root password to the machine. This is for security reasons.
![mediawiki4](https://cloud.githubusercontent.com/assets/3537889/14404324/be62723c-fe40-11e5-893d-033826eeb52e.jpg)
Next, confirm that MySQL has been installed and is working by running the command in your terminal: `mysql -u root -p`.
Enter your password when prompted. If all is well, you should receive a **mysql>** prompt, as in this screenshot.
![mediawiki5](https://cloud.githubusercontent.com/assets/3537889/14404330/de22ec1e-fe40-11e5-8338-5be63f1433b9.jpg)
Exit the prompt (**CTRL + D**), and run the script to secure the database: `sudo mysql_secure_installation`
Follow the instructions, and accept.
Discussion of the MySQL command line is beyond the scope of this tutorial. If you receive this prompt, you may proceed to the next step.
### Step 3: PHP for Lighttpd and MediaWiki
For this tutorial we will be installing PHP 5. Lighttpd and MediaWiki require several extra PHP modules (and configuration of same in Lighttpd's settings files) to work:
`sudo apt-get install php5 php5-fpm php5-mysql php5-cgi php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl`
![mediawiki6](https://cloud.githubusercontent.com/assets/3537889/14404367/db7b514e-fe41-11e5-9cf7-14d8f8042a40.jpg)
In particular, Lighttpd has nothing analogous to Apache's mod_php, so the php5-fpm module is required. A small change to PHP's FPM module is also necessary. To make this change, run the following command in your terminal: `sudo nano /etc/php5/fpm/php.ini`. This will open up the **php.ini** file.
Find the line containing **cgi.fix__pathinfo** and change the value to **1**, and then uncomment it by making sure there is no semicolon `;` in front of it like so: **cgi.fix__pathinfo=1**. Then, save your changes to the php.ini file by pressing **CTRL + X** so you can exit. You will be prompted for whether or not to save your changes and of course select to save.
![mediawiki7](https://cloud.githubusercontent.com/assets/3537889/14404391/af73f0b4-fe42-11e5-8a7e-9b2cb3c6c5e5.jpg)
### Step 4: MediaWiki
As stated, Ubuntu's MediaWiki package is rather out-of-date. We will download the latest stable branch; check releases.wikimedia.org/mediawiki/ for the highest numbered version, then download with either cURL or wget. We used `wget` by running the following command in the terminal:
`wget releases.wikimedia.org/mediawiki/1.26/mediawiki-1.26.2.tar.gz`
![mediawiki8](https://cloud.githubusercontent.com/assets/3537889/14404423/e2a42160-fe43-11e5-9590-c8e9de4ceebe.jpg)
Next, open and extract the tarball by running the command `tar -xvpf mediawiki-1.26.2.tar.gz` as shown in this screenshot:
![mediawiki9](https://cloud.githubusercontent.com/assets/3537889/14404427/064cdaee-fe44-11e5-9d73-42bc94b38e02.jpg)
And move it to the Lighttpd's document root, which should be /var/www/ (unless you've changed it) by running the following command:
`mv -v mediawiki-1.26.2/ /var/www/` as shown in the screencap:
![mediawiki10](https://cloud.githubusercontent.com/assets/3537889/14404436/73b6ccb6-fe44-11e5-93bc-2fae62710a9c.jpg)
Feel free to do a sanity check to see if all the files for the Mediawiki are there:
![mediawiki11](https://cloud.githubusercontent.com/assets/3537889/14404447/d5dd7fd4-fe44-11e5-9757-40bd44b2e370.jpg)
### Step 5: Linking it all together and wrapping up our operation
With this, all the pieces are in place. Everything that you need to have installed is installed. Now it's time to tell our SQL server process about the wiki.
Log into MySQL using the command line: `mysql -u root -p` and enter the password you've previously chosen from the previous steps in this tutorial for your MySQL database.
Create a new database for MediaWiki. (The default name is **my_wiki** although you can choose any name you wish so long as you edit MediaWiki's configuration later). To create a new database in MySQL for MediaWiki, run the following command : `create database mediawiki;` (NOTE: Don't forget that SQL commands terminate with a semi-colon!).
![mediawiki12](https://cloud.githubusercontent.com/assets/3537889/14404487/9729c1ca-fe45-11e5-8227-26643e75d9e2.jpg)
For security reasons, we should not use the root account to administer this database. SQL injection attacks are extremely common and only becoming more so; we therefore will not use the root MySQL account to operate on our MediaWiki install.
Instead, we'll create a new MySQL user account 'wikiuser' and grant it privileges to this database only by running the following command:
`grant index, create, select, insert, update, delete, alter, lock tables on mediawiki.* to 'wikiuser'@'localhost' identified by <yourpassword>;`
![mediawiki13](https://cloud.githubusercontent.com/assets/3537889/14404504/f45fe9dc-fe45-11e5-964d-076ea9503b38.jpg)
And then we want to flush privileges, like so:
![mediawiki14](https://cloud.githubusercontent.com/assets/3537889/14404520/814c12d0-fe46-11e5-87b6-a2651a947f4b.jpg)
You may now exit out of the MySQL prompt.
Next, we need to tell Lighttpd to use the **fastcgi** and **fastcgi-php** extensions:
`sudo lighty-enable-mod fastcgi fastcgi-php`
`sudo service lighttpd restart`
![mediawiki17](https://cloud.githubusercontent.com/assets/3537889/14404769/35dd12c6-fe4c-11e5-80f1-7e09b42481a2.jpg)
![mediawiki18](https://cloud.githubusercontent.com/assets/3537889/14404655/14ffb768-fe4a-11e5-9d1d-49f645a1e022.jpg)
(Incidentally, "lighttpd" is pronounced "lighty." The more you know!)
Now, point your browser to your WAN IP (or to localhost, as appropriate)/mediawiki-$VERSION
If all is well, you should see something like this:
![mediawiki19](https://cloud.githubusercontent.com/assets/3537889/14404763/11891492-fe4c-11e5-9b22-07485a283e28.jpg)
Click on the setup link. From here the install is fairly self-explanatory. A few things to note:
- Your MySQL db host will be localhost, *even if you are installing on a remote machine;* this is asking where the MySQL database is relative to the machine hosting the web server and MediaWiki itself.
![mediawiki20](https://cloud.githubusercontent.com/assets/3537889/14404818/63b2f624-fe4d-11e5-8431-080b4d8f9e4c.jpg)
- If you're following this guide, the Database Name parameter is mediawiki, and the user is wikiuser. The password should be the one you entered for the wikiuser MySQL account, not the root MySQL password. And the "table prefix" may be left blank.
- The default storage engine (InnoDB) and default character set (Binary) are fine.
- Choose a meaningful name for your wiki, keep the namespace the same, and enter secure credentials for the Admin account of the wiki.
![mediawiki22](https://cloud.githubusercontent.com/assets/3537889/14404820/771809a2-fe4d-11e5-9913-75639c2746b8.jpg)
- It is safe to say "I'm bored, just install the wiki already." Because, let's be real here, by this point you most likely are.
On the next page, save the LocalSettings.php file, and move it to the MediaWiki folder in your Lighttpd document root.
![mediawiki23](https://cloud.githubusercontent.com/assets/3537889/14404830/a8628f32-fe4d-11e5-9035-bd8d5349ee09.jpg)
![mediawiki24](https://cloud.githubusercontent.com/assets/3537889/14404843/13f33300-fe4e-11e5-8188-1a009ce0cfa2.jpg)
And that's it; you are done!
![mediawiki25](https://cloud.githubusercontent.com/assets/3537889/14404845/19320742-fe4e-11e5-9c88-b0fc31f456b9.jpg)
@jacqueline-homan
Copy link
Author

Setting Up MediaWiki With the Lighttpd Web Server on Ubuntu 14.04

by Jacqueline S. Homan

MediaWiki is a popular Wiki framework. It is a "webapp," meaning that instead of being installed like a traditional program, a tarball (or compressed/gzipped file) of scripts and PHP code is downloaded and decompressed into the document root (usually /var/www/http/, in our case /var/www/) of the server. The web server, usually Apache, can then serve the wiki up to other machines which access it over port 80 and the correct URL.

In this article, we will be installing the latest MediaWiki onto an Ubuntu 14.04.4 "Trusty Tahr" LTS host, using Lighttpd as our web server rather than Apache. The steps documented here will work on both a locally-installed copy of Ubuntu and on a remotely-hosted VPS such as Linode or Digital Ocean.

MediaWiki requires an SQL database backend and a PHP interpreter in order to work. We will be setting up what is known as a "LLMP stack" (Linux, Lighttpd, MySQL/MariaDB, PHP), where Lighttpd substitutes for Apache in the original "LAMP stack."

Additionally, while Ubuntu's repositories do offer a MediaWiki package, it is rather outdated. So we will be using wget or curl to download the latest release.

Prerequisites:

  • Ubuntu 14.04.4 OS, preferably amd64 arch
  • MySQL (or MariaDB) SQL server
  • PHP 5 packages
  • Lighttpd web server
  • cURL or wget

Procedure:

This tutorial assumes that you have already installed and configured Ubuntu 14.04.4, and that you have either root access or sufficient privileges via sudo. If not, contact your system administrator first.

Step 1: Lighttpd

Open a terminal and run the command sudo apt-get install lighttpd. Ubuntu will notify you of extra packages and suggest others. It is safe to simply approve of the requested actions. You may add the -y switch to the apt-get command to skip this check.

mediawiki1

The Lighttpd service will be started automatically. To restart (or stop, start, etc) the service, run the following command in your terminal: sudo service lighttpd restart (or stop, start, etc).

Verify that Lighttpd is working by pointing a web browser to your server's WAN-facing IP, or 127.0.0.1 if you're doing this locally.

mediawiki2

Lighttpd's configuration file resides at /etc/lighttpd/lighttpd.conf and files created by the daemon have the user- and groupname
www-data. The document root, which may be changed in the config file, defaults to /var/www/.

Step 2: MySQL

Next, run the command sudo apt-get install mysql-client mysql-server

mediawiki3

When prompted, enter a root password for the MySQL server. It is strongly advised that you do not reuse your Linux account password or, if present, the root password to the machine. This is for security reasons.

mediawiki4

Next, confirm that MySQL has been installed and is working by running the command in your terminal: mysql -u root -p.

Enter your password when prompted. If all is well, you should receive a mysql> prompt, as in this screenshot.

mediawiki5

Exit the prompt (CTRL + D), and run the script to secure the database: sudo mysql_secure_installation

Follow the instructions, and accept.

Discussion of the MySQL command line is beyond the scope of this tutorial. If you receive this prompt, you may proceed to the next step.

Step 3: PHP for Lighttpd and MediaWiki

For this tutorial we will be installing PHP 5. Lighttpd and MediaWiki require several extra PHP modules (and configuration of same in Lighttpd's settings files) to work:

sudo apt-get install php5 php5-fpm php5-mysql php5-cgi php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

mediawiki6

In particular, Lighttpd has nothing analogous to Apache's mod_php, so the php5-fpm module is required. A small change to PHP's FPM module is also necessary. To make this change, run the following command in your terminal: sudo nano /etc/php5/fpm/php.ini. This will open up the php.ini file.

Find the line containing cgi.fix__pathinfo and change the value to 1, and then uncomment it by making sure there is no semicolon ; in front of it like so: cgi.fix__pathinfo=1. Then, save your changes to the php.ini file by pressing CTRL + X so you can exit. You will be prompted for whether or not to save your changes and of course select to save.

mediawiki7

Step 4: MediaWiki

As stated, Ubuntu's MediaWiki package is rather out-of-date. We will download the latest stable branch; check releases.wikimedia.org/mediawiki/ for the highest numbered version, then download with either cURL or wget. We used wget by running the following command in the terminal:

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

mediawiki8

Next, open and extract the tarball by running the command tar -xvpf mediawiki-1.26.2.tar.gz as shown in this screenshot:

mediawiki9

And move it to the Lighttpd's document root, which should be /var/www/ (unless you've changed it) by running the following command:
mv -v mediawiki-1.26.2/ /var/www/ as shown in the screencap:

mediawiki10

Feel free to do a sanity check to see if all the files for the Mediawiki are there:

mediawiki11

Step 5: Linking it all together and wrapping up our operation

With this, all the pieces are in place. Everything that you need to have installed is installed. Now it's time to tell our SQL server process about the wiki.

Log into MySQL using the command line: mysql -u root -p and enter the password you've previously chosen from the previous steps in this tutorial for your MySQL database.

Create a new database for MediaWiki. (The default name is my_wiki although you can choose any name you wish so long as you edit MediaWiki's configuration later). To create a new database in MySQL for MediaWiki, run the following command : create database mediawiki; (NOTE: Don't forget that SQL commands terminate with a semi-colon!).

mediawiki12

For security reasons, we should not use the root account to administer this database. SQL injection attacks are extremely common and only becoming more so; we therefore will not use the root MySQL account to operate on our MediaWiki install.

Instead, we'll create a new MySQL user account 'wikiuser' and grant it privileges to this database only by running the following command:

grant index, create, select, insert, update, delete, alter, lock tables on mediawiki.* to 'wikiuser'@'localhost' identified by <yourpassword>;

mediawiki13

And then we want to flush privileges, like so:

mediawiki14

You may now exit out of the MySQL prompt.

Next, we need to tell Lighttpd to use the fastcgi and fastcgi-php extensions:

sudo lighty-enable-mod fastcgi fastcgi-php
sudo service lighttpd restart

mediawiki17

mediawiki18

(Incidentally, "lighttpd" is pronounced "lighty." The more you know!)

Now, point your browser to your WAN IP (or to localhost, as appropriate)/mediawiki-$VERSION

If all is well, you should see something like this:

mediawiki19

Click on the setup link. From here the install is fairly self-explanatory. A few things to note:

  • Your MySQL db host will be localhost, even if you are installing on a remote machine; this is asking where the MySQL database is relative to the machine hosting the web server and MediaWiki itself.

mediawiki20

  • If you're following this guide, the Database Name parameter is mediawiki, and the user is wikiuser. The password should be the one you entered for the wikiuser MySQL account, not the root MySQL password. And the "table prefix" may be left blank.
  • The default storage engine (InnoDB) and default character set (Binary) are fine.
  • Choose a meaningful name for your wiki, keep the namespace the same, and enter secure credentials for the Admin account of the wiki.

mediawiki22

  • It is safe to say "I'm bored, just install the wiki already." Because, let's be real here, by this point you most likely are.

On the next page, save the LocalSettings.php file, and move it to the MediaWiki folder in your Lighttpd document root.

mediawiki23

mediawiki24

And that's it; you are done!

mediawiki25
@jacqueline-homan

Write Preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment