User:Dan Nessett/Technical/How to set up a CZ clone on Ubuntu

This page provides instructions describing how to set up a Citizendium clone. Creating a CZ clone is useful for a number of purposes, including:


 * Storing a local copy of Citizendium on a lap-top or other device so articles are accessible when there is no available network connection.
 * Creating a local copy of Citizendium for the purpose of fixing bugs in the modified version of Mediawiki that forms its software base or developing extensions to that code.

Installing the necessary software infrastructure
CZ is implemented by a modified version of the Mediawiki software. This software relies on several software components that underly its operation, specifically:


 * PHP - an object-oriented interpreted language. Mediawiki is written in PHP and its software modules execute when accessed through a web server.
 * Apache2 - an open source industrial grade web server.
 * Postgres - an open source industrial grade database system.

Note that many Mediawiki implementations use the MySQL database system, rather than Postgres. While it might be possible to install Citizendium's wiki content using a MySQL database, doing so would represent experimental development. This how-to presumes the installer uses Postgres.

In order to install the Citizendium wiki software, the system running it must have PHP, Apache and Postgres preinstalled. So, the first step in creating a CZ clone is to install these software subsystems. There are a number of different platforms that support these and potentially any of them could be used to support a CZ clone, However, the most popular platform is Linux and the most popular of the Linux variants is Ubuntu Linux. Consequently, these instructions assume the software is installed on Ubuntu Linux (they should also work on any other Debian Linux variant). However, it is possible to install CZ's software on other Linux platforms and even on other operating systems (e.g., Mac OS X, Windows). Those interested in using using a different OS platform will have to do the research necessary to accomplish that. These instructions focus on using Ubuntu, specifically Ubuntu Hardy Heron (8.04LTS).

Installing the LAPP stack
It is common to refer to the Apache, Postgres and PHP software infrastructure as a LAPP stack (i.e., a Linux Apache Postgres PHP stack. An infrastructure using MySQL instead of Postgres is referred to as a LAMP stack). This section assumes the reader has already installed Ubuntu. Furthermore, it assumes the Ubuntu installation is standard (i.e., it includes all of the standard application software components). Many of the following instructions direct the installer to enter a command into a terminal window. On Ubuntu a terminal window is created as follows:



Updating the apt-get database
To ensure the LAPP stack installation uses the most up-to-date software, the installer should first update the apt-get database using the following command at a terminal command-line prompt:

sudo apt-get update

Install Postgres, Apache2 and PHP
After updating the apt-get database, install postgres.

sudo apt-get install postgresql-8.3 php5-pgsql

Then install the Apache2 web server and PHP.

sudo apt-get install apache2 libapache2-mod-php5 php5-gd

Configuring the LAPP stack
Once the LAPP stack is installed, the installer must configure it.

Configure Postgres
The first thing to do is assign a password to the postgres user of the postgres database. This step may be somewhat confusing to a novice user of postgres, so some explanation is in order. On the operating system that runs postgres is a user named postgres. This user is also listed as a Login Role for the postgres database system. The next step uses a feature of postgres that stipulates if you access the database (through the utility psql) as a particular user, you are automatically logged into postgres as that user. So, the first step is to use sudo to login as root and then change the user identity with the -u parameter. The command executed by sudo will use psql to connect to the postgres database (which, while having the same name, is different than the postgres Login Role). Once psql is connected to the postgres database using the Login Role postgres, it is possible to change the password for (the Login Role) postgres. Execute the following command at a terminal prompt:

sudo -u postgres psql postgres

This should result in a welcome message, followed by some command hints and then followed by the prompt:

postgres=#

At this prompt type:

\password

psql will prompt you for a password and then prompt you to reenter it (remember this password, because you will need it later). If you successfully enter the same password twice, psql returns a new prompt. Type "\q" (without the quotes), which should return you to a Ubuntu command prompt.

The above instructions use the term postgres in three different ways. There is the postgres database system, which is the software that implements postgres. There is the postgres database, which is a collection of tables managed by the postgres database system. Finally, there is the postgres Login Role, which is an identify used by the postgres database system to make access control decisions. It is necessary to keep these distinctions in mind. Later in these configuration instructions, we willl create a cz Login Role and a cz database.

For the novice, using postgres can be a frustrating experience. The main command line utility for interacting with postgres is "psql". Psql has two sets of commands. The first always begin with the character '\' (the backslash, not the slash). The second are SQL commands. Frequently, when using the second category of commands, a new user fails to enter the required semicolon (";") at the end. (The semicolon is not used at the end of the first category of commands). After entering an SQL command, psql returns a prompt and the user thinks the command has been executed. However, it hasn't. A semicolon must be entered (it can be entered after the command on the subsequent prompt). To make things even more confusing, psql uses a "query buffer". This concatenates all input until the requisite semicolon is typed. This also makes things difficult for the novice user, since many times he/she will type multiple commands and then remember to type one with a semicolon. This almost always results in an error. It is good practice to clean out the query buffer using the command "\r" (without the quotes) before entering a new SQL command. It is recommended that those unfamiliar with psql read this good tutorial on its use.

A GUI for accessing postgress databases, pgAdmin III, can help the novice user avoid many of the frustrations experienced when using psql. To install pgAdmin III, use Ubuntu's Add/Remove application facility. This is accessed by clicking at the top left of the desktop on the "Applications" tag (Postgres Figure 1). Select All available applications in the Show drop down menu and type postgres in the Search box (Postgres Figure 2). When the search finishes, scroll down to the bottom and select the pgAdmin III application by checking the box to the left. Then click on Apply Changes. This will install pgAdmin III on your system. (The system may request you to enable community applications. If so, click "Enable"). You will also have to enter your superuser password in a prompt window.

Once installed, pgAdmin III requires configuration. Start pgAdmin III (it should appear in the Applications menu under System Tools). The application window appears. In the left window pane is an icon labeled Servers(0). It is necessary to connect to a postgres server in order for the tool to operate. Under the File menu, select Add Server. A New Server Registration window pops up (Postgres Figure 3).

We are going to use the tool to connect to the database server on the local system. So, fill in the Name field with an appropriate name (e.g., Local Host) and fill in the Host field with the value localhost. The Username field is filled in by default to postgres. We will use this identity to access the database system until we have other Login Roles established. So, it is necessary to fill in the password created for the postgres Login Identity previously. Once this is filled in (leave all other selections at their default values), the OK button becomes active. Click it. You may see a hint displayed. If you find these annoying, there is a check box that turns them off. The result of this is a new entry under Servers(1) appears called Local Host (note the number of servers has changed from 0 to 1). Click on the + sign to the left of Local Host and a number of other labels appear.

We will use pgAdmin III to create two new Login Roles. The first is a role corresponding to your user name. This will allow you to use psql from your user account without specifying a username and password. Click on the Edit menu and select New Object. A pop out menu appears to the right. Select New Login Role.... Fill in the form as follows (Postgres Figure 4):


 * Role name - your user name on the system. For example if you login to Ubuntu as jdoe, fill in jdoe into the Role name field.
 * Password - enter a password for your postgres Login Role.
 * '''Password (again) - enter the same password.
 * Role Privileges - click all of the boxes. This gives you all privileges for database administration.

Click on OK.

To check that you successfully created a Login Role with the same username as your Ubunutu name, type the following command at a terminal window prompt (don't close pgAdmin III. We will use it again below):

psql postgres

This should result in the postgres welcome message, command hints and then the prompt: postgres=>. Type \q to exit psql.

Going back to pgAdmin III, we will create another Login Role as well as a new database. To create the Login Role follow the steps given above, except use the Role Name cz. While it is unnecessary to give the cz Login Role all privileges, this clone of CZ will be used by only you and it is therefore convenient to do so. If you were creating an installation of CZ that would be accessed by others, you would spend much more time configuring it so it is secure. How to configure a CZ installation so it is secure in a multi-user environment is outside the scope of these instructions.

Now that a cz Login Role is established, it is possible to create a cz database. In the main pgAdmin III window, click on the Databases label. Then either right click on Databases and select New Database or from the Edit Menu select New Database. FIll in the Name field with cz. Select cz using the right hand down-arrow of the Owner field (Postgres Figure 5). Click OK. The Databases field should change from Databases(1) to Databases(2). Click on the + sign to the left of the Databases field and two databases should be displayed: 1) postgres, and 2) cz (Postgres Figure 6).

This completes the configuration of postgres. We will return to postgres when we cover how to import the CZ dump data into the installation.

Configure Apache2
Configuring the apache2 web server requires less sophisticated tools than those used to configure postgres. Basically, a text editor is all that is required. These instructions use gedit, which is a nice GUI editor that comes pre-configued on Ubunutu.

Configuration of the original apache server required editing one large file (httpd.conf). Fortunately, the apache2 server software has separated the configuration information into several files, which makes configuration much easier. The main configuration file is located in /etc/apache2. It is named apache2.conf. There is no need to edit this file when setting up a CZ clone. In fact, no configuration of the apache2 server is necessary to enable the LAPP stack. To test that the apache2 server and PHP are correctly installed, in a terminal window cd to /var/www. Then enter the following command:

sudo gedit phpinfo.php

This will pop an edit window. Enter the following text into the file:



Then save the file.

In a web browser, create a new tab or a new window. In the url field at the top enter:

http://localhost/phpinfo.php

If the apache2 server and PHP are correctly installed, a page of information about PHP should display. At the top will be the PHP Version and in the subsequent graphical boxes will be information about PHP and the PHP extensions installed. It is useful to keep the phpinfo.php file in /var/www because occasionally it is helpful to test the apache2/PHP installation to ensure it retains integrity.

Some additional configuration of the apache2 server is necessary to utilize the CZ software that implements the wiki (this software is written in the PHP interpreted programming language). There are two ways to configure the apache2 server for the CZ clone. One way is to assume there is only one copy of the CZ software on the machine. This is normally true for those who are cloning CZ for personal use. The other way is to assume multiple copies of the CZ software exist on the machine. This is normally the case if the CZ clone is used for software development. While setting up the machine for multiple copies of the CZ software is unnecessary for a personal use clone, it really doesn't introduce any overhead to do so. Consequently, these instructions describe how to set up the apache2 server to access more than one copy of the CZ software.

The CZ software will be stored in subdirectories of /usr/local/src. The first step is to cd to that directory and create subdirectory called mediawiki. Change the permissions on mediawiki to 777 (i.e., in /usr/local/src executre sudo chmod 777 mediawiki). In a production environment, the adminstrator would use more careful access control permissions. However, since this CZ clone is intended for personal use, making the software world r/w is an acceptable configuration strategy. Change directories to mediawiki and create a CZ_1_13_2 subdirectory. Also make this directory world r/w. If the CZ clone is used for development purposes, the developer would create additional subdirectories of the /usr/local/src/mediawiki directory to hold different versions of the CZ software. In fact, it is possible to host copies of the non-modified mediawiki software by downloading them into subdirectories of mediawiki. For example, if it is desirable to download a copy of the mediawiki software on which CZ is based, the developer could create a subdirectory of mediawiki, say MW_1_13_2, and use it to hold the non-modified version.

Once this directory structure is created, it is possible to make the changes to the apache2 configuration information necessary to support the CZ software. In a terminal window cd to /etc/apache2/sites-enabled. Then exectute:

sudo gedit 000-default

This will open an edit window displaying the contents of the sites-enabled file. At the end of this file right before the  delimiter, enter the following information:

Alias /mediawiki/ "/usr/local/src/mediawiki/"  Options FollowSymLinks AllowOverride None 

Alias /CZ_1_13_2/wiki "/usr/local/src/mediawiki/CZ_1_13_2/phase3/index.php"

After doing so the end of the file should contain the following text:

Alias /mediawiki/ "/usr/local/src/mediawiki/"  Options FollowSymLinks AllowOverride None 

Alias /CZ_1_13_2/wiki "/usr/local/src/mediawiki/CZ_1_13_2/phase3/index.php"



Now restart the apache2 server by executing:

apache2ctl restart

We can't test whether the apache2 server properly executes the CZ software because that software isn't installed yet. However, we can test the configuration changes we just made. In a terminal window type:

sudo su cd /usr/local/src/mediawiki/CZ_1_13_2 mkdir phase3 chmod 777 phase3 cd phase3 cp /var/www/phpinfo.php. mv phpinfo.php index.php chmod 777 index.php exit

The first command sudo su moves the terminal session to the root identity. We do this because there are a lot of commands that require root access and typing sudo before each is inefficient. The last command exit takes the session back to your Ubunutu identity.

These commands make a copy of the phpinfo.php file in /usr/local/src/mediawiki/CZ_1_13_2/phase3 and rename it index.php. When we install the CZ software we will have to remove this file before loading it, since there is already an index.php file in the CZ software distribution.

Now we are prepared to test the new apache2 server configuration. Open a browser and either open a new tab or a new browser window. In the URL field enter:

http://localhost/mediawiki/CZ_1_13_2/phase3/index.php

The same PHP configuration information should appear as before. Now enter in the URL field:

http://localhost/CZ_1_13_2/wiki

Again the PHP configuration information should appear. If either of these tests fail, recheck the edits made to 000-default and the directory structure created above. In the latter case, the directories /usr/local/src/mediawiki, /usr/local/src/mediawiki/CZ_1_13_2 and /usr/local/src/mediawiki/CZ_1_13_2/phase3 should exist and with 777 permissions.

Installing the CZ wiki software
Installing the CZ wiki software requires access to the main CZ repository. In this repository is stored various versions of the software including the currently deployed version and others undergoing development. The version control system used to manage these versions is Subversion. We must install the Subversion software in order to access the repository.

Create a terminal window and enter the following command:

sudo apt-get install subversion

Once the installation completes, we can download the current CZ software release. But, first we have to clean up some detritus left from testing the apache2 configuration. Execute the following commands in a terminal window:

sudo su cd /usr/local/src/mediawiki rm -fr phase3 exit

This removes the phase3 directory and everything in it. Now we have to find out which release version we will checkout. Execute:

svn list /tags

The result is a list of releases for the CZ software. These instructions assume the latest version is called CZ_1_13_2_0.

The next step is to checkout this version. For those new to version control, a checkout from a repository makes a local copy of whatever branch is specified. This local copy retains information about where it comes from in the repository, but the repository itself keeps no state about the local copy. Consequently, you can do anything you want with the local copy, even delete it. The repository is unaware of these changes until you attempt to check in those changes.

To checkout CZ_1_13_2_0 into the directory CZ_1_13_2 (which is where the apache2 server expects to find it), execute:

cd /usr/local/src/mediawiki svn checkout /tags/CZ_1_13_2_0 CZ_1_13_2

The result of this command is a very large number of lines starting with the letter A (which stands for Add). After the command completes, there is a complete copy of the latest CZ software version in /usr/src/local/mediawiki/CZ_1_13_2.