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 http://trac.edgewall.org/wiki/TracOnWindows 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.
If you are looking for trac, that means that you are already know what svn is. You’ll need subversion client, such as http://tortoisesvn.net/downloads. 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 http://www.microsoft.com/visualstudio/en-us/try/trial-software.mspx – I hope 90 days will be enough to install trac
2. Donload free express version http://www.microsoft.com/express/vc/ and do the magic guided by http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/
The last thing create folder C:\src4trac\ – for sources. There will by lot of them Shourely you can create any folder you like.
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 http://www.python.org 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 easy-install-script.py (see http://bugs.python.org/setuptools/issue2).
- 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.
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
and it will download and install trac and everething trac needs. You can learn more about this tool here http://peak.telecommunity.com/DevCenter/EasyInstall. Pretty cool, but it’s not so easy to install easy_install on 64bits. See http://bugs.python.org/setuptools/issue2. So let’s do the folowing.
- Create C:\src4trac\SetupTools folder and checkout with tortoisesvn from http://svn.python.org/projects/sandbox/branches/setuptools-0.6
- Download 64bitlauncher.patch http://bugs.python.org/setuptools/issue2 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
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
and now we can finaly type
python setup.py install
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
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 http://trac.edgewall.org/wiki/TracDownload 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 http://genshi.edgewall.org/wiki/Download and put unziped/untared code to C:\src4trac\Genshi. Now do the following
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
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 _fcgi.py. 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 http://pypi.python.org/pypi/python-fastcgi 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 http://www.fastcgi.com/drupal/node/5 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_SOCKET_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\setup.py 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
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
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:
#!/usr/bin/python # -*- 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 http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. # # Author: Jonas Borgström import os try: os.environ['TRAC_ENV'] = "C:/TracProjects/TestProj" from trac.web import fcgi_frontend fcgi_frontend.run() except SystemExit: raise except Exception, e: print 'Content-Type: text/plain\r\n\r\n', print 'Oops...' print print 'Trac detected an internal error:' print print e print import traceback import StringIO tb = StringIO.StringIO() traceback.print_exc(file=tb) 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\fcgi_frontend.py 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 http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. # # 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) s.serve_forever() if __name__ == '__main__': run() pkg_resources.require('Trac==%s' % VERSION)
There is a time for looking if we are on the right way.
Run from command line
and you should get
unknown listenType (0)
If you do – then it’s greate! If you get indent errors -read http://www.secnetix.de/olli/Python/block_indentation.hawk 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\api.py 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')
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
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
<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 http://trac.edgewall.org/wiki/TracSubversion 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 http://subversion.tigris.org/getting.html#windows 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 http://svnbook.red-bean.com/en/1.1/ch01s05.html (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 http://svn.collab.net/repos/svn/tags/1.5.2 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 http://www.swig.org/. Download http://prdownloads.sourceforge.net/swig/swigwin-1.3.39.zip for example and unzip it to C:\src4trac\swig folder. After that download APR from http://apr.apache.org/download.cgi 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. http://www.zlib.net – 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 http://www.webdav.org/neon/ and unzip it to C:\src4trac\svnTheGreate\Neon
Open comand line type
gen-make.py -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
rmdir /q %_psb%svn
rmdir /q %_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
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
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