Thursday, April 15, 2010

Installing Trac (mod_wsgi, Apache 2.2, Python 2.6, PostgreSQL 8.4) on Windows XP

Installation


Too many pieces to put together here. The following components of the installation are available as Windows installers; just download and install them in the order listed before continuing with the rest:

Apache 2.2
Python 2.6
PostgreSQL 8.4
subversion 1.6.6
svn-python a.k.a Python subversion bindings
psycopg

Creating the PostgreSQL database

Launch pgAdmin III (Start > All Programs > PostgreSQL 8.4 > pgAdmin III). In the pane to the left of the window, right-click your PostgreSQL database (usually labelled "PostgreSQL 8.4 (localhost:5432)") and select "Connect". Supply the password. The tree expands to list all objects in this database.

Right click on the "Login Roles" node and select "New Login Role...".

Fill out the fields to create a new role.

Right click on the "Databases" node and select "New Database...".

Fill out the fields to create a database for Trac to use. Set the owner to the same user created in the previous step as a security measure.

Installing Trac

Trac 0.11.47

Installing mod_wsgi

Download mod_wsgi-win32-ap22py26-3.0.so to a temporary directory. Rename the file to mod_wsgi.so and copy it to the modules subdirectory of your Apache installation (usually C:\Program Files\Apache Software Foundation\Apache2.2\modules).

Locate httpd.conf under the conf subdirectory of the Apache installation (usually C:\Program Files\Apache Software Foundation\Apache2.2\conf) and open it in a text editor. Find the lines starting with LoadModule and insert the following line there:
    LoadModule wsgi_module modules/mod_wsgi.so

Creating a Trac Site

Creating a Trac instance/site:

Run the following command from the command prompt:
    trac-admin path-to-desired-location initenv

Note that you may have to specify the full path to trac-admin as shown here:
    c:\python26\scripts\trac-admin path-to-desired-location initenv

You will be prompted for the following:
  • Project Name
  • Database connection string
  • Repository type
  • Path to repository
For the database connection string, use the following format:
    postgres://user:pass@localhost:5432/dbname?schema=schemaname
If you are following the strings from the screenshots, the corresponding connection string would be:
    postgres://testtrac:password@localhost:5432/testtrac?schema=testtrac
This will create your Trac site. You can do a trial run by saying:
    tracd --port 8000 trac-site-location
...and then visiting http://localhost:8000/ using your web-browser.

Configuring mod_wsgi for the site

Run the following command at the command prompt. Replace "temporary-directory" with the name of a temporary folder where the required scripts for your Trac site will be generated.
    trac-admin trac-site-location deploy temporary-directory
This command will create two folders within "temporary-directory" -- cgi-bin and htdocs. You will find the properly configured WSGI script for your site in temporary-directory\cgi-bin\trac.wsgi. Open the trac.wsgi in a text editor, prefix all path strings using the back-slash ('\') with the letter 'r'. For example, if you find this:
    environ.setdefault('trac.env_path', 'C:\MyProject\Trac\ExampleSite')
...prefix the path string with the letter 'r' like this:
    environ.setdefault('trac.env_path', r'C:\MyProject\Trac\ExampleSite')
I am assuming this to be a bug with how Trac works on Windows paths. Read about Python's raw strings to find out more about this. Create a folder called apache within your Trac site and copy the generated trac.wsgi there. Open httpd.conf, scroll to the bottom and add the following there:
    WSGIScriptAlias /trac "trac-site-location/apache/trac.wsgi"

    <Directory "trac-site-location/apache">
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>

No comments:

About Me

My photo
C/C++ Programmer doing CAD on Windows. Some web development experience. Bangalorean.

Blog Archive

Labels