How to set up Gitweb

apache-2.2gitperl

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?

Best Answer

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.