Computer and me

April 15, 2009

Install Trac on 64 bit Windows and run it under IIS7 fast cgi.

Filed under: Uncategorized — Tags: — er2v @ 10:02 pm

As a windows user, I realy like to download latest versions of sofware, because they have bugfixes ( and brand new bugs 🙂 I also love everething that is 64bit, and as an ASP.NET developer I love IIS7. So when I decided to install trac to organise our team’s development process, I’ve opened and started from the begin. This article is some kind of the step by step tutorial of how to make it 64 bit IIS7 fast cgi.

Simple things

If you are looking for trac, that means that you are already know what svn is. You’ll need subversion client, such as I’m pretty shure you already have it. Second thing you need is Visual Studio VC++ to cmpile sources. If you don’t have it – you can do the following:

1. Download and install trial professional edition – I hope 90 days will be enough to install trac 🙂

2. Donload free express version and do the magic guided by

The last thing create folder C:\src4trac\ – for sources. There will by lot of them 🙂  Shourely you can create any folder you like.

Install Python

First, that I’ve read was that I need Python. I was surprised that trac is written on Python. I’ve never used python before, but alway’s whanted to try. So without bothering myself with reading of what I need I went  to and downloaded 64 bit 2.6.2 python installer. I have not noticed

Notes regarding 64 bit Python:

  • SetupTools does not yet provide an install that works with 64-bit Python, it’s nevertheless possible to use the (see
  • The Subversion project does not provide amd64 or ia64 setup executables, so if you want to use Subversion integration, you’ll need to either compile the bindings yourself, or use the x86 version of Python.
  • It’s generally hard to find pre-compiled extensions, so you most often have to compile them yourself (e.g. for Genshi, Mercurial, the bindings for the DB backends) 

But I realy heapy about not noticed that. I’ve had very intersting week 🙂

So, go ahead, install 64 bit Python 2.6.2 or later.

Install easy_install

The second thing we’ll not be able to enjoy trac without is easy_install. Easy install is cool thing, it’s helps install different python programs easily. So you can type in command line

easy_install trac

and it will download and install trac and everething trac needs. You can learn more about this tool here Pretty cool, but it’s not so easy to install easy_install on 64bits :). See So let’s do the folowing.

  1. Create C:\src4trac\SetupTools folder and checkout with tortoisesvn from
  2. Download 64bitlauncher.patch to C:\src4trac\SetupTools folder and apply it (context menu -> tortisesvn->apply patch)

Now you have cli-64.exe and gui-64.exe files in C:\src4trac\SetupTools\setuptools directory. Open command line (press winkey-r and type cmd) and type

cd C:\src4trac\SetupTools\setuptools
rename cli.exe cli-old.exe
rename cli-64.exe cli.exe
rename gui.exe gui-old.exe
rename gui-64.exe gui.exe

go to C:\src4trac\SetupTools\ typing

cd ..

and now we can finaly type

python install


easy_install --help

and if you get error add C:\Python26\Scripts to the PATH environment variable and reload command line.

Congratulations we’ve overjumped first problem. It was not so hard, and now we can install trac itself 🙂

Install Trac and Genshi

If you have internet connection without proxy server – then simply type

easy_install trac

It will do all the job.

If you have proxy on computer you install trac or if you don’t have internet connection on this computer at all then download from other computer from zip or tar of laterst trac(not the installer) and put it’s unziped/untared content to C:\src4trac\Trac. After that download genshi tar or zip from and put  unziped/untared code to  C:\src4trac\Genshi. Now do the following

cd C:\src4trac\trac
easy_install .
cd C:\src4trac\Genshi
easy_install .

So that’s it! We have trac installed! But that’s only the beginning of the problems 🙂

But let’s forget about them for now and let’s do some checks,  if everething is alright.

Checking if everething is ok till now

Create folder C:\TracProjects. Type

trac-admin c:\ TracProjects\TestProj initenv

Ansver all questions. Actualy you can always press enter except in the path to the repository question where you should provide path to the subversion repository.

tracd --port 8000 c:\TracProjects\TestProj

Open http://localhost:8000/TestProj.
It’s alive!!! Alive!!!
If it’s not – then you have to reread all above very carefuly.

Running Trac under IIS 7, fast cgi

Standalone server is good, but hard to manage. So it’s much better to use some more powerful server such as IIS. We can run it trac as CGI but it’s not an option – too slow. The very reasonable way to make it run under IIS is it’s new FastCGI module. But here we can read

Note for Windows: Trac’s FCGI does not run under Windows, as Windows does not implement Socket.fromfd, which is used by If you want to connect to IIS, your choice may be AJP.

As for me AJP is realy strange thing and not an option – I want FastCGI.  So if trac’s fcgi does not support Windows, then we need to find other FCGI module for python. So let’s download and put code to C:\src4trac\PyFCGI folder. Do you think it’s all? No. The most interesting part starts right now.

Download The Development Kit from and put the code to the C:\src4trac\FastCgiKit Open C:\src4trac\FastCgiKit\Win32\FastCgi.dsw. If you get error

Connot load project due to a corrupt project file.

on opening projects – you should open dsp files in the text editor that supports conversion between Unix format and windows format. Notepad++ is the right thing. So after the conversion solution will open with all projects.

Visual studio will open.  Config_h project will be unavailable – it’s ok. Now you should open Main menu -> Build-> Configuration Manager

Set Active solution configuration: Release. Set Active Solution Platform x64. If there is only win32 option – click on <New> and in Type or select new platform: select x64, Copy settings from Win32.Leave checkbox about creation new platform checked. Cntrl-shift-B. Does not complile. Right.

open C:\src4trac\FastCgiKit\fcgi_config.h and comment following lines :

#define HAVE_NETDB_H 1
#define HAVE_SYS_PARAM_H 1
#define HAVE_SYS_TIME_H 1

Now you are finally able to  compile the code 🙂

Compiled? Good. So now you can fynaly install python-fastcgi. But first open C:\src4trac\PyFCGI\ in editor and replace

c_ext = Extension("fcgi", ["fastcgi/pyfcgi.c"], libraries=["fcgi"],


c_ext = Extension("fcgi", ["fastcgi/pyfcgi.c"], libraries=["libfcgi"],

Be carefull about indents on copy/paste.

Now you can

cd C:\src4trac\PyFCGI
easy_install .

Copy libfcgi.dll from C:\src4trac\FastCgiKit\libfcgi\Release to C:\Python26\Lib\site-packages\python_fastcgi-1.1-py2.6-win-amd64.egg\fastcgi

For testing if it’s all right run in command line

import fastcgi

If it’s not – reread and redo.

Changing code of trac 🙂

Create C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin directory and a file trac.fcgi with the following content:

# -*- coding: utf-8 -*-
# Copyright (C) 2003-2009 Edgewall Software
# Copyright (C) 2003-2004 Jonas Borgström
# All rights reserved.
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at
# Author: Jonas Borgström 

import os

    os.environ['TRAC_ENV'] = "C:/TracProjects/TestProj"
    from trac.web import fcgi_frontend
except SystemExit:
except Exception, e:
    print 'Content-Type: text/plain\r\n\r\n',
    print 'Oops...'
    print 'Trac detected an internal error:'
    print e
    import traceback
    import StringIO
    tb = StringIO.StringIO()
    print tb.getvalue()

As you can remember C:/TracProjects/TestProj is the place where we’ve created test environment for trac. Pretty long way 🙂 I’m tired of typing alredy 🙂
There is not much left to do. Now open C:\tracbackup\trac-0.11.4-py2.6.egg\trac\web\ file and replace it’s code with following:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C)2005-2009 Edgewall Software
# Copyright (C) 2005 Matthew Good
# All rights reserved.
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at
# Author: Matthew Good

import pkg_resources

from trac import __version__ as VERSION
from trac.web.main import dispatch_request

import fastcgi

def run():
    s = fastcgi.ThreadedWSGIServer(dispatch_request, workers=1)

if __name__ == '__main__':
    pkg_resources.require('Trac==%s' % VERSION)

There is a time for looking if we are on the right way.
Run from command line

python C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin\trac.fcgi

and you should get
unknown listenType (0)
If you do – then it’s greate! If you get indent errors -read 🙂 If some other error – reread and redo.

One more last thing you need to do. Open C:\tracbackup\trac-0.11.4-py2.6.egg\trac\web\ find

path_info = property(fget=lambda self: self.environ.get('PATH_INFO', '').decode('utf-8'),
                            doc='Path inside the application')

and replace it with

    path_info = property(fget=lambda self: self.environ.get('PATH_INFO','').decode('utf-8').replace(self.environ.get('SCRIPT_NAME', ''), ''),
                     doc='Path inside the application')

Configure IIS7

Create application pull, named trac and without managed code. Create appliction named trac in the default web site called trac aimed on C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\htdocs in trac application pool.
Create virtual directory in your trac appliction called cgi-bin pointed on C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin.

In trac application open Handler Mappings, click Add module mapping…  and  fullfill form with the following values:

Request Path: *trac.fcgi

Module: FastCgiModule

Executable(optional):  c:\Python26\python.exe|C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin\trac.fcgi

Yes it’s right. With | symbol. Last field is name – feel free in naming it as you want 🙂

Open your browser. Deep breath.


If it works – you are lucky. If not – set rights on folder c:\Python26 for


There is one more posible bug. Open C:\Python26\Lib\site-packages. There is folders wich ends on .egg. If there is files wich ends with .egg – it’s zip archive. Unzip it to the folder with exactly same name wich have file in the same folder. For example if you have

C:\Python26\Lib\site-packages\genshi-0.5.1-py2.6-win-amd64.egg file – you should inzip it’c content to the C:\Python26\Lib\site-packages\genshi-0.5.1-py2.6-win-amd64.egg folder. This bug is about PYTHON_EGG_CACHE environment variable. Google it if you want:)

So now – it should work. Trac on IIS 7 on fast cgi! Wow! We are greate. Is it the end of our journey? No.


To be completely heappy – we need to be able to login. First of all turn on Basic Authentification for trac application in Autherization in IIS management console.
After that open C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\htdocs\web.config file and add

<location path=”cgi-bin/trac.fcgi/login”>
<add accessType=”Deny” users=”?” />

as a first level child of <configuration> tag. Actualy you can configure security in any way you like, per user or per role.

Trac and Subversion

Trac and subversion are made for each other 🙂  You can read about it. This article is for unix. As a Windows user we will do everething in our way :).
Actualy when you need to connect to the subversion repository from trac – you need python bindings of subversion’s dll’s so Trac could do all subversion can. Happyly subversion project include everething you need for such bindings.

Note. When you compile subversion python bindings – you will get subversion + subversion python bindings. Someone can deside to use this compiled subversion binaries not onle for bindings, but for the subversion itself too. I recomend not to do so and do the following – compile subversion bindings for python and use them for trac. But for the subversion functionality itself get subversion binaries from and instal subversion, create repository and checkin something there and live heapyly. Why? Becouse if you compile them for truck only – you don’t need ssl libraries, berkley db libraries and so on, becouse truck will not use them anyway. You can use minimal number of subversion satellite projects – so the less code you’ll need to compile – the less problems you’ll get 🙂

If you already have subversion 1.x.y. installed then you need to create bindings of 1.x.y. We will make 64bit bindings. Don’t worry – it does not matters how many bits have your installed subversion. If you don’t have subversion yet – download the version you like and install it. Create repository. If you don’t cnow how – read (till the end;))

I have had subversion version 1.5.2 so I had to make my bindings for this version. So let’s do so. First create folder C:\src4trac\svnTheGreate – to show our respect for subversion :). Checkout Planty of files.
So while you are reading C:\src4trac\svnTheGreate\subversion\bindings\swig\INSTALL – I’ll go get some cofee. It will take you some time 🙂
So welcome back. As you’ve read, you need Download for example and unzip it to C:\src4trac\swig folder. After that download APR from and unzip it to the C:\src4trac\svnTheGreate\apr folder. Download latest APR -util and put it to the C:\src4trac\svnTheGreate\apr-util folder. So let’s compile them. In 64 bit. Let-s start from apr.
It’s simple. Release. x64. Build.
Now open C:\src4trac\svnTheGreate\apr-util\aprutil.dsw. There will be 4 projects that contains iconv in name. They will be unawalable. Never mind. Open C:\src4trac\svnTheGreate\apr-util\include\apu.hw file and set #define APU_HAVE_APR_ICONV 0 instead of 1.
So Release, x64. Build.
Dont worry about _bdb_ projects – you just don’t need them. 6 project’s will fail. Not more.
Now you should do the folowing.

Copy folders Release and LibR from C:\src4trac\svnTheGreate\apr-util\x64 to C:\src4trac\svnTheGreate\apr-util\
Copy folders Release and LibR from C:\src4trac\svnTheGreate\apr-util\x64 to C:\src4trac\svnTheGreate\apr-util\
Copy folder LibR from C:\src4trac\svnTheGreate\apr-util\xml\expat\lib\x64 to C:\src4trac\svnTheGreate\apr-util\xml\expat\lib\

Download Zlib. – and unzip it to the C:\src4trac\svnTheGreate\zlib folder. We do not need to compile it. It will be compiled later with bindings.
Download Neon and unzip it to C:\src4trac\svnTheGreate\Neon

Open comand line type

cd C:\src4trac\svnTheGreate -t vcproj --with-swig="C:\src4trac\swig" --vsnet-version=2008

and look how does magic happens.

Open C:\src4trac\svnTheGreate\subversion_vcnet.sln and compile it. Release! 64bit!

All java perl and ruby projects will fail – do not worry, we don’t need them. But if libsvn_fs fails – this is fatal.
If it’s not compile – reread. You must be mised something. Is apr and apr-util compiled in 64 bits? Have you moved folders from x64 and so on.

Now create c:\src4trac\BindingsInstaller.bat

@echo off
::Standard commission
SET _svn=C:\src4trac\svnTheGreate\
SET _psb=C:\Python26\Lib\site-packages\

rmdir /q %_psb%svn
rmdir /q %_psb%libsvn

md %_psb%svn
md %_psb%libsvn

xcopy %_svn%subversion\bindings\swig\python\svn\*.py %_psb%svn
xcopy %_svn%subversion\bindings\swig\python\*.py %_psb%libsvn
xcopy %_svn%Release\subversion\bindings\swig\python\*.dll %_psb%libsvn

cd %_psb%libsvn

ren _client.dll _client.pyd
ren _core.dll _core.pyd
ren _delta.dll _delta.pyd
ren _diff.dll _diff.pyd
ren _fs.dll _fs.pyd
ren _ra.dll _ra.pyd
ren _repos.dll _repos.pyd
ren _wc.dll _wc.pyd

xcopy %_svn%Release\subversion\libsvn_client\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_delta\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_diff\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_fs\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_fs_fs\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_fs_util\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra_local\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra_neon\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_ra_svn\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_repos\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_subr\*.dll %_psb%libsvn
xcopy %_svn%Release\subversion\libsvn_wc\*.dll %_psb%libsvn
xcopy %_svn%\Release\subversion\bindings\swig\python\libsvn_swig_py\*dll %_psb%libsvn
xcopy %_svn%apr\Release\*.dll %_psb%libsvn
xcopy %_svn%apr-util\Release\*.dll %_psb%libsvn

Run it. Two folders should appear in C:\Python26\Lib\site-packages. They are svn and libsvn with following content



svn should start working now

The End

I’ve spent 2 weeks to find the ways. Nothing worked from the first time, and there were no any infomation via google. So I’ve decided to write my experience down in a very detailed way. I know, that it just can’t be too detailed. This article is valuable for the following reasons: Trac on IIS 7 fast cgi – no information in internet at all. Second reason is detailed instructions on subversion python bindings 64 bits. It has it’s tricks like x64 directories. Thank you for spending your time on reading this tutorial. Hope it was usefull. Comment please 🙂



  1. а у тебя IIs7 на какой оси стоит ?

    Comment by Bug0r — April 19, 2009 @ 6:46 am

  2. windows server 2008

    Comment by er2v — April 19, 2009 @ 8:45 am

    • we are using ruby clone of trac called RedMine ( I like it more then trac.

      Comment by bug0r — April 27, 2010 @ 3:45 pm

  3. Hello,

    Thank you for this detailed procedure.

    However, I’m stack trying to compile the fcgi. When opening the solution in C++ 2008 Express the only projects that open successfully are authorizer, echo_cpp, and libfcgi. The other projects showed a message “Cannot load the project due a corrupt project file”

    Do you mind to put your compiled version somewhere in the net, or send it to my e-mail.


    Comment by harold — June 12, 2009 @ 4:12 pm

    • Hello, harold.
      Actually they are not corrupted. This project files have Linux end of lines. I think someone have open them in linux text editor and saved. But it’s easy to fix. You can download Notepad++ from Then you should open “corrupted” project files in it. In main menu choose Format -> Convert to Windows format. Save. Close. Now it will be fine.

      Actually I decided to put all src4trac folder to internet. You can download it from here.

      It’s russian site, so it’s in russian language. But all you need to do is enter numbers and press green button

      After that you’ll be redirected to the page wich will automatically start downloading after 10 seconds. Good luck 🙂

      Comment by er2v — June 13, 2009 @ 6:57 am

      • Hello Alex,

        Thank you for the files. I will give them a try. Have a nice one.

        Comment by harold — June 21, 2009 @ 1:07 pm

  4. Hello,

    I am having a problem with the following part:
    ‘Copy libfcgi.dll from C:\work\Python\flup\fcgi-2.4.0\libfcgi\Release to C:\Python26\Lib\site-packages\python_fastcgi-1.1-py2.6-win-amd64.egg\fastcgi’

    Where does the C:\work\Python\flup\fcgi-2.4.0\libfcgi\Release comes from? did i miss something during the previous parts?


    Comment by Bart Stevens — June 14, 2009 @ 5:26 pm

    • Sorry. My mistake. C:\src4trac\FastCgiKit\libfcgi\Release
      it should be here

      Comment by er2v — June 14, 2009 @ 5:32 pm

  5. hm.. strange

    Comment by boy forced to strip — July 20, 2009 @ 3:29 am

    • What is strange?

      Comment by er2v — July 20, 2009 @ 8:00 am

  6. Hi.
    Thank you for the very good tutorial. Just one question. Could someone re-upload the src4trac.7z file? It’s offline 😦
    Thanks in advance

    Comment by benurb — September 19, 2009 @ 7:39 pm

    • Sorry for late answer. I’ve reuploaded it, If you still need it 🙂
      It’s here now

      Comment by er2v — October 11, 2009 @ 6:15 pm

  7. I too noticed that faststcgi.ThreadedWSGIServer works only with one worker thread for anything complex, which is very sad. Helloworld-type apps, however, can use multiple workers without problems. Any ideas on why this happens?

    Comment by RommeDeSerieux — October 2, 2009 @ 10:05 am

    • No ideas 😦 I’m not a python guy

      Comment by er2v — October 11, 2009 @ 6:19 pm

  8. Wow, thanks man, you saved me some hours of grief. Rally thanks.

    Comment by Camilo — October 11, 2009 @ 6:12 am

  9. Just a question, I thought I was done, but I had to come back for more info.

    What do you mean by “So Release, x64. Build.” What is the specific procedure to do that?

    Comment by Camilo — October 11, 2009 @ 8:40 am

    • No there is not. Just select this settings in build configuration manager.

      Comment by er2v — October 11, 2009 @ 6:23 pm

  10. Really struggled with this task on a local 64 bit server 2008 dev box berore I load it on one of our web servers.

    It is probablly just me too tiered now but I find this tutorial, whilst helpfull, quite disjointed going off a tangents that seem to lead nowhere.

    I do note others seem to have taken to it straight away which makes it doubly frustrating.

    Eventually decided to attempt to pull the compiled file

    down only to find after entering the code the file never starts to downlod.

    If someone else has a copy of these files available it would be really appreciated.


    Comment by Stevejay — October 23, 2009 @ 9:32 am

  11. Huge help! You are my hero 🙂
    Thanks for the great manual.

    Comment by der Igel — March 24, 2010 @ 9:56 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: