So, as the title says, we’re going to install trac on apache using mod_fastcgi.
Now, before we get off, some explanation on why I write this:
As it is, I tried to follow the documentation on the official trac website. But it was unclear, and made me very confused. In the end, someone had to tell me how simple it was before I wanted to believe it in the first place…
In this small post, I’ll assume you have a trac environment configured.
Two steps
Yes indeed, just two steps are required. In here, I’m going to assume you either have a website running already, or you are going to create a virtualhost for trac.
In the end, I’ll post my own virtualhost, so that everyone can reference on that.
Step one
First, you have to “deploy” the trac environment. This is done with the following command:
trac-admin /path/to/env deploy /path/to/apache/htdocs
Now, one thing to really keep in mind is that you cannot deploy in the env directory (or by my experience anywhere near it) It’s best to simply use the /var/www/htdocs most apache setups use.
Step two
Now, we configure apache. In the virtualhost section you want trac to run in, you add the following:
ScriptAlias /trac /path/to/apache/www/cgi-bin/trac.fcgi/
The trailing slash is really important, otherwise the cgi app won’t see the page as argument!
Also, you can alias straight to / if you want, it will work too (if you don’t share this virtualhost with another app)
Note: If you’re running (or going to run) multiple trac instances through apache, you should go to /path/to/apache/htdocs/cgi-bin/ and edit trac.fcgi to change TRAC_ENV to TRAC_ENV_PARENT_DIR:
os.environ['TRAC_ENV'] -> os.environ['TRAC_ENV_PARENT_DIR']
Test it
Albeit this is not the third step (there is no third step), it’s best to take a look and test. But you should see the trac pages coming up pretty quickly, and you should be pleased, for it is the simpelest thing to configure.
As I promised, this is my own virtualhost, just to make sure people might learn from it:
<VirtualHost *:80>
FastCGIExternalServer /home/user/project/fcgi.fcgi -socket /home/user/project/scgi.sock
ServerName project.com
DocumentRoot /home/user/project/
Alias /media /home/user/project/media/
ScriptAlias /trac /var/www/htdocs/cgi-bin/trac.fcgi/
RewriteEngine On
RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/trac.*$
RewriteRule ^/(.*)$ /fcgi.fcgi/$1 [QSA,L]
</VirtualHost>
Note that this virtualhost is also hosting a django config, and I have added a RewriteRule to make sure /trac isn’t handled by it. Which was a huge stumble point before, and therefore I thank the great people at the #trac channel on irc.freenode.net !
As always, any comments, improvements, or even thanks are welcomed!