Edgewall Software

Changes between Version 18 and Version 19 of TracOnGentoo


Ignore:
Timestamp:
Mar 19, 2005, 8:22:13 PM (19 years ago)
Author:
anonymous
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • TracOnGentoo

    v18 v19  
    27272005-03-18: It looks like the link to the "[http://home.dju.elegiac.net/wiki/wiki/MultipleTracInstancesOnGentoo really nice guide]" doesn't work.
    2828[[br]]''There is still a version on Google Cache. Maybe we should copy it to this page!?''
     29
     30
     31Installing Trac on Gentoo for multiples projects
     32
     33I wanted to use Trac for each development project I had, and configure the Apache 2 webserver on my Gentoo Linux box to create a (name-based) virtual host that would hold every Trac instance (more information on virtual hosts can be found here). The following is what I did, as root, to make the whole thing work.
     34
     35Say the development vhost is known as dev.domain.tld. Basically I wanted to access to each project website via http://dev.domain.tld/projectX/.
     361. Emerging Trac
     37
     38Since mod_python support is a new feature of 0.7.1 and is still experimental, I'm not going to use it and I'll stick with a simple CGI installation. You'll see that using a CGI installation together with webapp-config on a single vhost causes a restriction: the version of every Trac instance has to be unique. Using mod_python may throw away this restriction, I'll update this document as soon as I test it.
     39
     40emerge trac
     41
     42Obviously, I had to edit /etc/portage/package.keywords to make stuff available to Portage, because I'm running a stable (x86) version of Gentoo.
     43
     44app-text/silvercity             ~x86
     45dev-libs/clearsilver            ~x86
     46www-apps/trac                   ~x86
     47
     482. Installing each instance of Trac
     49
     50Say I have now a bunch of projects, known as project1, project2, ... I use the webapp-config tool to install each instance of Trac 0.7.1:
     51
     52webapp-config -I -h dev.domain.tld -d project1/trac trac 0.7.1
     53webapp-config -I -h dev.domain.tld -d project2/trac trac 0.7.1
     54...
     55
     56Don't forget the /trac part for the directory path.
     57
     58For each project, symlinks (or hardlinks, depending on your webapp-config configuration) are created in /var/www/dev.domain.tld/htdocs/projectX/trac/ and /var/www/dev.domain.tld/htdocs/projectX/trac/css/, making images and css files available in the web space, under http://dev.domain.tld/projectX/trac/ and http://dev.domain.tld/projectX/trac/css/. Symlinks are known to work with Trac.
     59
     60Furthermore, a symlink (or hardlink) to trac.cgi is created each time in /var/www/dev.domain.tld/cgi-bin/, regardless of the instance. This webapp-config issue can be restricting if you want to install different versions of Trac on the same vhost, because this way you get only one trac.cgi per vhost. As a result, you need to install the same version of Trac everywhere on your vhost.
     613. Setting up Subversion repositories and Trac environments
     62
     63Now, let's create Subversion repositories, one for each project we have.
     643.1. Creating Subversion repositories
     65
     66Let's say we want our repositories to live under /var/svn/. Issue the following commands to create a repository for project1:
     67
     68svnadmin create /var/svn/project1
     69chown -R apache /var/svn/project1
     70
     71Changing the ownership of the repository is important: as svn commits will be handled by Apache, the apache user needs to have write access to the repository.
     72
     73Also, if you built Subversion from Apache 2.0.50, you may want to do the following (that's because APR from Apache 2.0.50 has a bug and set created directories to 1755 instead of regular 0755):
     74
     75find /var/svn/project1 -type d -exec chmod 755 {} \;
     76
     77Repeat these steps for each project you have.
     783.2. Creating Trac environments
     79
     80Each project needs a Trac environment too, and we want them to live under /var/lib/trac/. If it doesn't already exist, we create the directory:
     81
     82mkdir /var/lib/trac/
     83
     84Then we create a Trac environment for project1 by doing:
     85
     86trac-admin /var/lib/trac/project1/ initenv
     87
     88Just answer the question to fill you needs, and indicates the right Subversion repository created in the previous step. Adjust the ownership of var/lib/trac/project1/, because Trac needs to write in it:
     89
     90chown -R apache /var/lib/trac/project1/
     91
     92Repeat the above steps for each project you have.
     934. Configuring Apache
     94
     95Here is my configuration for the name-based vhost.
     964.1. Vhost configuration
     97
     98The first part of the configuration is relative to the vhost itself:
     99
     100<VirtualHost *:80>
     101        ServerName dev.domain.tld
     102        DocumentRoot /var/www/dev.domain.tld/htdocs
     103
     104        <Directory /var/www/dev.domain.tld/htdocs>
     105                AllowOverride all
     106                Options +Indexes +FollowSymLinks
     107
     108                <IfModule mod_access.c>
     109                        Order Deny,Allow
     110                </IfModule>
     111        </Directory>
     112
     113        <Directory /var/www/dev.domain.tld/cgi-bin>
     114                Options +FollowSymLinks
     115
     116                <IfModule mod_access.c>
     117                        Order Deny,Allow
     118                </IfModule>
     119        </Directory>
     120
     121Here I set the name-based vhost and the access policies. Note that +Indexes on htdocs/ isn't needed; however, in case webapp-config created symlinks, +FollowSymLinks is necessary, both on htdocs/ and cgi-bin/.
     1224.2. Per-project configuration
     123
     124Next, there are per-project specific directives that define a project. This example has to be repeated for each project.
     125
     126        ###
     127        ### project1
     128        ###
     129        Alias /project1/dox /var/www/dev.domain.tld/htdocs/project1/dox
     130
     131        <Location /project1/svn>
     132                <IfDefine SVN>
     133                        DAV svn
     134                        SVNPath /var/svn/project1
     135                        SVNIndexXSLT /project1/trac/svnindex.xsl
     136                </IfDefine>
     137
     138                <LimitExcept GET PROPFIND OPTIONS REPORT>
     139                        AuthType Basic
     140                        AuthName "project1::svn"
     141
     142                        <IfModule mod_auth_ldap.c>
     143                                AuthLDAPURL ldap://ldap.domain.tld:389/ou=users,dc=domain,dc=tld?uid?one
     144                                Require group cn=project1,ou=dev,ou=groups,dc=domain,dc=tld
     145                        </IfModule>
     146                </LimitExcept>
     147        </Location>
     148
     149        <Location /project1>
     150                SetEnv TRAC_ENV "/var/lib/trac/project1"
     151        </Location>
     152
     153        <Location /project1/login>
     154                AuthType Basic
     155                AuthName "project1::trac"
     156
     157                <IfModule mod_auth_ldap.c>
     158                        AuthLDAPURL ldap://ldap.domain.tld:389/ou=users,dc=domain,dc=tld?uid?one
     159                        Require group cn=project1,ou=dev,ou=groups,dc=domain,dc=tld
     160                </IfModule>
     161        </Location>
     162
     163        Alias /project1/trac /var/www/dev.domain.tld/htdocs/project1/trac
     164        ScriptAlias /project1 /var/www/dev.domain.tld/cgi-bin/trac.cgi
     165
     166As you can see, I make a big use of Locations and Aliases. Now, some comments.
     1674.2.1. Trac stuff
     168
     169We need several directives to make Trac work. The first thing is to set the TRAC_ENV environment variable. This variable indicates to trac.cgi the location of the Trac environment corresponding to project1 in the filesystem. Actually, I'm storing every Trac environment under /var/lib/trac/, so the projectX Trac environment can be found under /var/lib/trac/projectX/.
     170
     171That's why we set the TRAC_ENV for the entire /project1 web space, with the following:
     172
     173        <Location /project1>
     174                SetEnv TRAC_ENV "/var/lib/trac/project1"
     175        </Location>
     176
     177Then we redirect every request for /project1/* to trac.cgi with the ScriptAlias directive:
     178
     179        ScriptAlias /project1 /var/www/dev.domain.tld/cgi-bin/trac.cgi
     180
     181This needs to be placed at the very end of the project configuration, because it is a default redirection for every request made to /project1/*. Special configuration for some URIs will be placed before this directive to be taken in account.
     182
     183A needed escaping URI is /project1/login, used by Trac to authenticate users. I've set a Location for it, and placed the authentication stuff inside:
     184
     185        <Location /project1/login>
     186                AuthType Basic
     187                AuthName "project1::trac"
     188
     189                <IfModule mod_auth_ldap.c>
     190                        AuthLDAPURL ldap://ldap.domain.tld:389/ou=users,dc=domain,dc=tld?uid?one
     191
     192                        Require group cn=project1,ou=dev,ou=groups,dc=domain,dc=tld
     193                </IfModule>
     194        </Location>
     195
     196AuthType, AuthName and Require directives are needed, then you may use the user referential you want (here I'm using a LDAP server). I'm telling Apache that a user may authenticate if he belongs to the project1 group. This way, you can create groups for each project you have, and make users belong to the groups corresponding to the projects they work on.
     197
     198The last thing to make Trac work is to map a URI to the images and css files location, again to escape the trac.cgi handler.
     199
     200        Alias /project1/trac /var/www/dev.domain.tld/htdocs/project1/trac
     201
     202As we installed the Trac instance to /project1/trac it should work. Well, actually we need to modify the trac.ini configuration file for Trac, in order to change the way URIs are generated. Just edit /var/lib/trac/project1/conf/trac.ini:
     203
     204htdocs_location = /project1/trac
     205
     206Ok, that should be enough to use Trac. Point a browser to http://dev.domain.tld/project1 and voila.
     2074.2.2. External components to Trac
     208
     209Then I felt the need to add external pages to Trac, like a Doxygen component that would contain the generated documentation from the code source of project1. I wanted to find this documentation under /project1/dox.
     210
     211We need to escape trac.cgi again, by setting a new Alias before the ScriptAlias directive. There we map the /project1/dox web space to the /var/www/dev.domain.tld/htdocs/project1/dox file space.
     212
     213        Alias /project1/dox /var/www/dev.domain.tld/htdocs/project1/dox
     214
     215By the way, I've automated the creation of the Doxygen documentation by using the post-commit hook of Subversion, and doing a checkout followed by a "doxygenation" inside /var/www/dev.domain.tld/htdocs/project1/dox.
     216
     217Last but not least, I wanted to make the Subversion repository accessible via /project1/svn, with anonymous checkouts and authenticated commits. We need a Location to place the mod_dav_svn stuff and the authentication directives.
     218
     219        <Location /project1/svn>
     220                <IfDefine SVN>
     221                        DAV svn
     222                        SVNPath /var/svn/project1
     223                        SVNIndexXSLT /project1/trac/svnindex.xsl
     224                </IfDefine>
     225
     226                <LimitExcept GET PROPFIND OPTIONS REPORT>
     227                        AuthType Basic
     228                        AuthName "project1::svn"
     229
     230                        <IfModule mod_auth_ldap.c>
     231                                AuthLDAPURL ldap://ldap.domain.tld:389/ou=users,dc=domain,dc=tld?uid?one
     232                                Require group cn=project1,ou=dev,ou=groups,dc=domain,dc=tld
     233                        </IfModule>
     234                </LimitExcept>
     235        </Location>
     236
     237As you can see, I'm storing my Subversion repositories under /var/svn/, so I set the name of the project1 repository to /var/svn/project1. Obviously, it is the filepath I will use when I create the project1 Trac environment.
     238
     239Instructions for limiting the write access to the repository can be found on the SVN Book. I'm using the same authentication scheme than the previous one, to be consistent between Trac users and SVN users.
     2404.2.3. Integrating these external components inside Trac
     241
     242We can use the per-project templates of Trac to integrate, for example, the Doxygen documentation inside Trac. They are located under /var/lib/trac/project1/templates/. We may want to insert a link to /project1/dox in the header, and have the following site_header.cs:
     243
     244<?cs
     245####################################################################
     246# Site header - Contents are automatically inserted above Trac HTML
     247?>
     248<div>
     249<a id="dox" href="/<?cs var:project.name?>/dox">Doxygen documentation</a>
     250</div>
     251
     252And why not using a per-project css file? Let's edit site_css.cs:
     253
     254<?cs
     255##################################################################
     256# Site CSS - Place custom CSS, including overriding styles here.
     257?>
     258@import url("<?cs var:htdocs_location ?>css/<?cs var:project.name?>.css");
     259
     260This way, we can create a /var/www/dev.domain.tld/htdocs/project1/trac/css/project1.css file (among with symlinks), and personalize the Trac layout. These per-projects file won't be deleted by webapp-config, so it's a good thing.
     2615. Conclusion
     262
     263By copy/pasting the configuration for one project, we can set up as many projects as we want, each with their own web space, Subversion access, authentication scheme (users referential and authentication method) and layout.
     264
     265Corrections and suggestions about this documentation are welcome.