Configuring Gitweb for Apache on Debian

[git.ithinksw.org](http://git.ithinksw.org/) is a pretty nifty site: in addition to providing Gitweb when you access it via a web browser, it also allows cloning of repositories in the same namespace. So, for example, you can visit [http://git.ithinksw.org/ITFoundation.git](http://git.ithinksw.org/ITFoundation.git), and receive a Gitweb-generated interface to the repository, but you can also run `git clone http://git.ithinksw.org/ITFoundation.git` to clone the repository. [tycho](http://tychoish.com/) is also a fan of Git, and was interested in setting a similar site up for his own repositories, so I've decided to share my configuration here. Goals ----- My servers tend to run [Debian GNU/Linux](http://debian.org/), because I am totally in love with dpkg and APT. I generally like being able to rely on automatic updates to my software, and Gitweb should be no exception, so this configuration uses the copy of Gitweb that is maintained by dpkg. [git.ithinksw.org](http://git.ithinksw.org/) also runs git-daemon to support the git:// protocol. One of the features of git-daemon is support for per-user public_git directories. Of course, Apache has the [mod_userdir](http://httpd.apache.org/docs/2.2/mod/mod_userdir.html) module to provide a similar feature over HTTP. With a little [mod_rewrite](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html) hackery, the git:// and http:// clone URLs for every repository are identical, and every repository has a Gitweb interface. The configuration ----------------- This configuration relies on two things: * A valid Gitweb configuration, including a directory that contains symbolic links to repositories and public_git directories for use as the Gitweb root. Unfortunately, this does require some manual maintenance, to ensure that the desired repositories and users show up in Gitweb. That said, I find this to be useful: I can "hide" repositories or users from Gitweb whilst maintaining their ability to be cloned. * The VirtualHost configuration in Apache. Here is an example of the layout of the server's filesystem (paths followed by lines that begin with -> are symbolic links to the following path): /home/user/public_git/repository.git /srv/git/git.ithinksw.org/ITFoundation.git /srv/www/git.ithinksw.org/gitweb/gitweb.conf /srv/www/git.ithinksw.org/gitweb/root/ITFoundation.git -> /srv/git/git.ithinksw.org/ITFoundation.git /srv/www/git.ithinksw.org/gitweb/root/\~user -> /home/user/public_git Here is the relevant gitweb.conf: $projectroot = "/srv/www/git.ithinksw.org/gitweb/root"; $git_temp = "/tmp"; $home_text = "indextext.html"; $projects_list = $projectroot; $stylesheet = "/gitweb.css"; $logo = "/git-logo.png"; $favicon = "/git-favicon.png"; @git_base_url_list = qw(git://git.ithinksw.org http://git.ithinksw.org); $site_name = "git.ithinksw.org"; $home_link_str = "git.ithinksw.org"; $projects_list_description_width = "200"; $feature{'pathinfo'}{'default'} = [1]; Here is the VirtualHost configuration for Apache: DocumentRoot /srv/git/git.ithinksw.org UserDir public_git UserDir enabled # gitweb SetEnv GITWEB_CONFIG /srv/www/git.ithinksw.org/gitweb/gitweb.conf Alias /gitweb.css /usr/share/gitweb/gitweb.css Alias /git-logo.png /usr/share/gitweb/git-logo.png Alias /git-favicon.png /usr/share/gitweb/git-favicon.png ScriptAlias /gitweb /usr/lib/cgi-bin/gitweb.cgi RewriteEngine on # redirect userdir listing to gitweb search RewriteRule ^/?(~[^/]+)/?$ /?s=$1 [R] # rewrite all other paths that aren't git repo internals to gitweb RewriteRule ^/$ /gitweb [PT] RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /gitweb%{REQUEST_URI} [L,PT] Closing ------- That's all there is to it! I do hope that you'll read the documentation for the tools I've employed here, so that you may fully understand what is going on. This will give you a very basic setup similar to the one at [git.ithinksw.org](http://git.ithinksw.org/), but you'll need to know what's going on to further customize or improve on what I've provided. Good luck, and do let me know if you improve on these beginnings or have any suggestions!