Friday, September 30, 2016

How To Set Up the Latest MediaWiki with Lighttpd on Ubuntu 14.04

This article was originally written to provide a Technical Writing sample. 

Introduction


MediaWiki is a popular open source wiki platform that can be used for public or internal collaborative content publishing. MediaWiki is used for many of the most popular wikis on the Internet including Wikipedia, the site that the project was originally designed to serve.
In this guide, we will be setting up the latest version of MediaWiki on an Ubuntu 14.04 server. We will use the lighttpd web server to make the actual content available, php-fpm to handle dynamic processing, and mysql to store our wiki's data.

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.
Before we install any packages, we should also log into our server with our sudo user and update our local package index.
sudo apt-get update
This will download a package list from the software repository sources that are configured on your server and update the package list with information on the newest versions of available packages and their dependencies.
Once you've taken care of all of prerequisites and updated your server, you're ready to get started with this guide.


Step One — Install MySQL


MySQL is a popular open source relational database management system (RDBMS) that is used to store and manage the data in many web applications.
In this step, we will start by downloading and installing MySQL from the official Ubuntu repositories using apt, the package tool that is used to retrieve, configure, install and remove software packages in Ubuntu. After the software has been installed, we will configure the database for our MediaWiki installation.
To install MySQL, type:
sudo apt-get install mysql-server
You will be asked to create a root (administrative) password. This should be a secure, unique password that will only be used for MySQL. Remember this password because you'll need it later.
Next, you will need to generate the directory structure that MySQL will use to store its databases and information.
sudo mysql_install_db
At this point, it's a good idea to secure MySQL. Fortunately, there is a program that will help you to improve the security of your default MySQL installation.
sudo mysql_secure_installation
This program will prompt you to implement several recommended security improvements, like removing anonymous-user accounts and test databases that can be accessed by all users.
Recommendations for mysql_secure_installation
You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
Finally, we will create a unique database and user for MediaWiki. For security reasons, it is recommended that you use one (non-root) user per database.
To do this, we will need to log in to the database.
sudo mysql -u root -p
We will then add a new database called <^>mwdb<^>, a user called <^>mwuser<^>, and we will be setting a password <^>mwpass<^>. For your installation, choose a more secure password than <^>mwpass<^>. Also, make sure you record the database, database user, and password because you'll need these to complete the MediaWiki installation.
CREATE DATABASE mwdb; CREATE USER mwuser@localhost IDENTIFIED BY 'mwpass'; GRANT index, create, select, insert, update, delete, alter, lock tables on mwdb.* TO mwuser@localhost;
These commands will create a database and a user and will grant database permissions to the user. However, you will need to tell the server to reload the grant (permission) tables before the changes take effect.
custom_prefix(mysql>) FLUSH PRIVILEGES;
Once this is done, you can exit the database using the exit command.
custom_prefix(mysql>) EXIT


Step Two — Install and Configure Lighttpd and PHP


Lighttpd is a secure and flexible open source web server that is optimized for high performance environments that we will use to display web pages to our site visitors.
In this step, we will use apt to install the lighttpd and php packages from the Ubuntu repositories. After the software is installed, we'll need to do some additional configuration to ensure that lighthttpd can utilize php-fpm.
To install lighthttpd, type:
sudo apt-get install lighttpd
This will install lighthttpd and start the service once the installation finishes. We can test the status of the server by typing your IP address into a web browser. We should see the Lighttpd placeholder page.
lighthttpd

Next, install php and php-fpm.
sudo apt-get install php5-fpm php5
We will also want to install the following packages to support the MediaWiki installation:
sudo apt-get install php5-mysql php-apc php5-intl imagemagick
Now that we've installed lighthttpd, php, and the supporting packages, we'll want to enable php in lighttpd by modifying the '/etc/php5/fpm/php.ini' file using nano, a command line text editor.
sudo nano /etc/php5/fpm/php.ini
You'll want to uncomment the cgi.fix_pathinfo=1: option by removing the ; at the beginning of the line. Make sure you save and close the file.
Next, we'll need to update the lighttpd php configuration file to use php-fpm.
sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
The configuration file should look like this:
/etc/lighttpd/conf-available/15-fastcgi-php.conf

/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" )) ) ```
Save and exit the file.
Next, we'll need to enable the php-fpm FastCGI process manager by running the following commands:
sudo lighttpd-enable-mod fastcgi sudo lighttpd-enable-mod fastcgi-php
Finally, we'll need to reload lighttpd:
sudo service lighttpd force-reload
At this point we can confirm that php-fpm is working correctly by creating a PHP file called phpinfo.php in the lighttpd web directory.
sudo nano /var/www/phpinfo.php
Enter the following text into the file:
/var/www/phpinfo.php

Save and exit the file. Now we can load phpinfo.php in a browser by going to http://<^>server ip<^>/phpinfo.php. If you see the Server API FPM/FastCGI line, then you know that everything is working as expected.

php info

[WARNING] Warning: Before proceeding, you'll want to remove the 'phpinfo.php' file. While this file is very useful for troublshooting and debugging, it contains sensitive information that could be used to comprimise your server. <$>
sudo rm /var/www/phpinfo.php
Once you've removed the phpinfo.php file, you're ready to move on to the next step.


Step Three - Install MediaWiki


In this step, we will download, install, and configure the latest MediaWiki package.
First, we'll download the MediaWiki package:
cd /tmp sudo wget https://releases.wikimedia.org/mediawiki/1.27/mediawiki-1.27.0-rc.1.tar.gz
This will download a compressed archive file named 'mediawiki-1.27.0-rc.1.tar.gz' from wikimedia to a temporary folder.
Next, we will need to extract the file and move it to the lighthttpd web directory.
sudo tar -xvzf mediawiki-1.27.0-rc.1.tar.gz sudo mkdir /var/www/mediawiki sudo mv mediawiki-1.27.0-rc.1/* /var/www/mediawiki
Now that you've downloaded the MediaWiki files, you can proceed to the next step.


Step Four — Complete the MediaWiki Installation


Now that you have your files in place and your software is configured, you can complete the MediaWiki installation through the web interface.
To start the installer, navigate to your server's public IP address or domain name and run through the configuration wizard at 'http://<^>server ip<^>/mediawiki'. This page will tell you that the LocalSettings.php file is not found. Click on the 'Please set up the wiki first.' link and you will be guided through the wiki setup. At the end of this step, a 'LocalSettings.php' file will be generated.
Installer
First, you will be asked to select your language.

Language

Next, an environment check will run to determine if any packages are missing or if there are any configuration issues.

Env Check

The third screen will ask you to connect to a database.
  • If you have followed this guide, your database will be installed on the same server as the MediaWiki installation and you will select 'localhost' for the 'Database host'.
  • Use the database name, username, and password for the <^>mwdb<^> database that we created in step one.
  • In most cases, the 'Database table prefix' can be left blank. This prefix is usually only used if you need to share a database between multiple applications.
Database

You should use the default database settings (Storage engine: InnoDB, Database character set: Binary) as recommended by the installer.

DB Config Settings

You will then be asked to name your wiki and provide credentials for your administrator account.

Wiki Name

You will also be asked if you would like for the installer to 'Ask me more questions' or 'I'm bored already, just install the wiki'. If you choose to be asked more questions, the installer will ask you to configure several additional settings, including user permissions, copyright information, email configuration, user experience, optional extensions, image uploads, and caching.

Credentials
Once you finalize the configuration, a LocalSettings.php file will be downloaded. You will need to download the and put it in the base of your wiki installation (the same directory as index.php).

LocalSettings Download
However, it may be easier to create a LocalSettings.php file and paste the contents of the downloaded file into the LocalSettings.php file that you created:
sudo nano /var/www/mediawiki/LocalSettings.php
You should now be able to access your wiki at http://<^>server ip<^>/mediawiki/.


Conclusion


Your new MediaWiki site should now be configured and ready to use on your Ubuntu 14.04 server. Using this website, you will be able to directly publish and modify content from a web browser.

No comments:

Post a Comment