How to set up Gitweb
I have set up Git on a server, using gitosis to control commit access. I would like to configure my Git system so that anyone inside our firewall can have read access to the Git repository, and I would like to set up Gitweb as well.
I have found several Gitweb setup tutorials on various blogs, but they differ in various details and some of them are out-of-date. I'd like this question to have an up-to-date answer.
My specific setup is Red Hat Enterprise Linux. I have successfully installed Git, gitosis, and the Gitweb and Apache packages. However, I have not figured out how to configure Apache to actually grant access to Gitweb.
How do I set up my server to allow read-only access to Git, and to allow Gitweb to work?
After you install gitweb (on RHEL $ yum install gitweb
), it should create a directory var/www/git
and put a file in etc/httpd/conf.d/git.conf
. If these don't exist, create them. Put all your git repos in var/www/git
and edit git.conf
to let it execute cgi scripts and rewrite URLs for gitweb. Here's what I have:
<Directory /var/www/git>
SetEnv GITWEB_CONFIG /etc/gitweb.conf
DirectoryIndex gitweb.cgi
Allow from all
AllowOverride all
Order allow,deny
Options +ExecCGI
AddHandler cgi-script .cgi
<Files gitweb.cgi>
SetHandler cgi-script
</Files>
RewriteEngine on
RewriteRule ^[a-zA-Z0-9_-]+.git/?(\?.)?$ /gitweb.cgi%{REQUESTURI} [L,PT]
</Directory>
There is also a gitweb.conf file in /etc/gitweb.conf
which points to things like css, favicons and logos. I'm pretty sure those will work if you leave your projects in /var/www/git, but if you change that directory, you'll probably need to put it in gitweb.conf.
Tested out on Ubuntu 8.04:
sudo apt-get install apache2 git-core gitweb
sudo a2enmod rewrite
Assuming that you git projects are in /pub/git
, edit the file: /etc/gitweb.conf
$projectroot = "/pub/git";
$git_temp = "/tmp";
#$home_link = $my_uri || "/";
$home_text = "indextext.html";
$projects_list = $projectroot;
$stylesheet = "/gitweb.css";
$logo = "/git-logo.png";
$favicon = "/git-favicon.png";
# enable human readable URLs
$feature{'pathinfo'}{'default'} = [1];
Now, setup a new virtual host in Apache config directory. Edit a new file called: /etc/apache2/sites-available/gitweb
<VirtualHost *>
ServerName git.mydomain.com
ServerAlias git
DocumentRoot /pub/git
SetEnv GITWEB_CONFIG /etc/gitweb.conf
RewriteEngine on
RewriteRule ^/$ /gitweb [PT]
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /gitweb%{REQUEST_URI} [L,PT]
# Aliases
ScriptAlias /gitweb /usr/lib/cgi-bin/gitweb.cgi
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
# Logfiles
ErrorLog /var/log/apache2/gitweb.error.log
CustomLog /var/log/apache2/gitweb.access.log combined
</VirtualHost>
Enable the new site:
sudo a2ensite gitweb
Restart Apache:
sudo invoke-rc.d apache2 restart