DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:dokuwiki_trac_lighttpd_integration

Integrating DokuWiki with Trac trough lighttpd

This is not a “nice” integration. No code change in DokuWiki or Trac is necessary. All the magic is done with lighttpd's url rewrites and redirects. If you are looking for a more sophisticated integration, this is definitely not the place where to find it!

That said, here is what works:

  • linking from Trac tickets to DokuWiki pages
  • linking from Dokuwiki to Trac tickets
  • Trac is accessible at http://your.domain.org/trac
  • Trac runs as fcgi

What does not work:

  • separate authentication is necessary for DokuWiki and Trac
  • links from DokuWiki pages to Trac tickets are displayed as invalid (but working)
  • links from Trac tickets to DokuWiki pages are displayed as invalid (but working)

If you already tried to set up Trac to work with lighttpd at root URL, you have probably bumped into this problem. According to the thread, the issue is in how lighttpd deals with root URLs. Even when using “fix-root-scriptname” ⇒ “enable”, Trac gets the base URL wrong sometimes (my experience). However, all problems seem to magically disappear when Trac runs at relative URL like ./trac or so. And that is exactly what this tip is about.

As mentioned earlier all the magic is done with url rewrites and redirects. It is expected that your DokuWiki install uses nice URL like http://yourdomain.org/something:start. We will not discuss here php-fcgi configuration or authentication methods, although you need some sort of authentication configured in your lighttpd.conf, otherwise you won't be able to log into Trac. Please consult TracInstall on how to install Trac and initialize your Trac environment.

You need to have these modules enabled in your lighttpd.conf

  • mod_rewrite
  • mod_redirect
  • mod_alias
  • mod_access
  • mod_fcgi

Here goes lighttpd's config (the relevant part):

$HTTP["host"] =~ "^yourdokuwiki.org" {
 
        var.dokudir = "/dokuwiki"
        var.tracdir = "/path/to/Trac-0.11.4-py2.5.egg/trac"
        server.document-root = "/path/to/htdocs" + var.dokudir
        
        #authentication, necessary for Trac. DokuWiki does not rely on server's auth. facilities.
        auth.require = ("/trac/login" => (
                "method" => "basic",
                "realm" => "login",
                "require" => "valid-user"
                ),
        )
        
        # make sure those are always served through FastCGI and never as static files
        static-file.exclude-extensions = ( ".php" )
        
        # deny access completely to these
        $HTTP["url"] =~ "/(\.|_)ht" { url.access-deny = ( "" ) }
        $HTTP["url"] =~ "^/(bin|data|inc|conf)/"  { url.access-deny = ( "" ) }

        # static content & fcgi for trac
        alias.url = ("/trac/chrome/common" => var.tracdir + "/htdocs")
        $HTTP["url"] =~ "^/trac/chrome/" {
        # do nothing if url points to static content
        }
        else $HTTP["url"] =~ "^/trac" {
                fastcgi.server = ( "/trac" => ( "trac" => (
                                                "socket" => "/tmp/trac-fastcgi.sock",
                                                "bin-path" => var.tracdir + "/web/fcgi_frontend.py",
                                                "check-local" => "disable",
                                                "bin-environment" => ("TRAC_ENV" => "/path/to/environment"),
                                                "fix-root-scriptname" => "enable",
                                                        ),
                                                ),
                                )
        }
        # rewrites for dokuwiki
        $HTTP["url"] =~ "^" { index-file.names = ("doku.php") }
        
        url.rewrite = (
        "^/lib/.*$"              => "$0",
        "^/.*ticket[0-9]{1,10}$" => "$0",
        "^/trac/.*$"             => "$0",
        "^/trac$"                => "/trac/",
        "^/_media/(.*)\?(.*)$"   => "/lib/exe/fetch.php?media=$1&$2",
        "^/_media/(.*)$"         => "/lib/exe/fetch.php?media=$1",
        "^/_detail/(.*)?\?(.*)$" => "/lib/exe/detail.php?media=$1&$2",
        "^/_detail/(.*)?$"       => "/lib/exe/detail.php?media=$1",
        "^/_export/([^/]+)/(.*)" => "/doku.php?do=export_$1&id=$2",
        "^/doku.php.*"           => "$0",
        "^/feed.php.*"           => "$0",
        "^/(.*)\?(.*)"           => "/doku.php?id=$1&$2",
        "^/(.*)"                 => "/doku.php?id=$1"
        )
        url.redirect = (
        "^/trac/wiki/(.*$)" => "/$1",
        "^/.*ticket([0-9]{1,10})$" => "/trac/ticket/$1"
        )
}

The important point here is that url.redirects (external) are done after url.rewrites (internal), so we do not want lighttpd to rewrite any URL starting with /trac/ (ending with ticket123 etc.) prior to redirection.

How it behaves

Dokuwiki side

This internal DokuWiki link is intercepted and points to Trac

[[*:trac]] points to http://yourdokuwiki.org/trac

However, links below are treated as DokuWiki links and point to Dokuwiki pages

[[*:trac:]] points to http://yourdokuwiki.org/trac:start
[[*:trac:start]] points to http://yourdokuwiki.org/trac:start
[[*:trac:something]] points to http://yourdokuwiki.org/trac:something
[[*:trac:something:something]] points to http://yourdokuwiki.org/trac:something:something

A link in any DokuWiki page like the one below redirects you to the corresponding Trac ticket

[[ticket123]] points to http://yourdokuwiki.org/trac/ticket/123

Trac side

URLs below point to Trac and are not converted

http://yourdokuwiki.org/trac
http://yourdokuwiki.org/trac/
http://yourdokuwiki.org/trac/timeline
...
...

Internal Trac links in tickets can point to DokuWiki pages

[wiki:start] points to http://yourdokuwiki.org/start
[wiki:wiki:syntax] points to http://yourdokuwiki.org/wiki:syntax

You can also disable Trac's internal Wiki in /your-environment/conf/trac.ini .

Written by –Kamil, January 2010

tips/dokuwiki_trac_lighttpd_integration.txt · Last modified: 2010-01-20 17:26 by 87.197.129.85

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki