03 Feb 2010, 12:00

Setting up Gitweb on Debian


There are many blog posts and howtos about setting up gitweb on the web. Unfortunately none of those seems to work for me. Either you can’t check out via http or it’s just not working.

Here is my configuration, which works for me on Debian Lenny. If you follow this instructions you’ll get a working gitweb Webinterface, checkouts via HTTP and git URLs.

First create a new directory to hold the git repositories. I’ll use the FHS compliant /srv/git:

mkdir /srv/git

Then create a new Apache 2 Vhost:

<virtualhost *:80>
ServerName git.example.net
ServerAdmin you@example.net
SetEnv  GITWEB_CONFIG   /etc/gitweb.conf
DocumentRoot    /srv/git
ErrorLog /var/log/apache2/git.example.net-error.log
CustomLog /var/log/apache2/git.example.net-access.log combined
HostnameLookups On
UseCanonicalName Off
ServerSignature Off

Alias /gitweb.css /usr/share/gitweb/gitweb.css
Alias /git-favicon.png /usr/share/gitweb/git-favicon.png
Alias /git-logo.png /usr/share/gitweb/git-logo.png
Alias /git /srv/git

ScriptAlias /gitweb.cgi /usr/lib/cgi-bin/gitweb.cgi
DirectoryIndex gitweb.cgi
<directory /srv/git>
AllowOverride None
Options Indexes FollowSymlinks
Order Allow,Deny
Allow From All

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}         !-f
#RewriteCond %{REQUEST_FILENAME}        !-d
RewriteRule ^.* /gitweb.cgi/$0          [L,PT]
# for debugging rewrite rules
#RewriteLog /srv/www/git.gauner.org/logs/rewrite.log
#RewriteLogLevel 9

In most tutorials you’re told to include the RewriteCond matching directories (!-d), but for me that broke pretty URLs, so I disabled it.

If you use lighttpd, check out this FAQ entry.

Now you’ll need to make some adjustments to /etc/gitweb.conf:

$projectroot = "/srv/git";

# turn off potentially CPU-intensive features
$feature{'search'}{'default'} = [undef];
$feature{'blame'}{'default'} = [undef];
$feature{'pickaxe'}{'default'} = [undef];
$feature{'grep'}{'default'} = [undef];
$feature{'snapshot'}{'default'} = [undef];

# nicer-looking URLs (req. apache rewrite rules)
$feature{'pathinfo'}{'default'} = [1];

$site_name = "git.example.net";
$my_uri = "http://git.example.net";

# target of the home link on top of all pages
$home_link = $my_uri || "/";

@git_base_url_list = ("git://git.example.net");

Restart the Apache and checkout if your Vhost works.

Finally you can setup the OpenBSD inetd in /etc/inetd.conf add this line:

git     stream  tcp     nowait  nobody  /usr/bin/git-daemon git-daemon --inetd --verbose --base-path=/srv/git /srv/git

Now you’re done. Of course you need to install apache2, gitweb and openbsd-inetd but that should be clear ;)

Go here or here for more information.