Install Gitweb to a Subdirectory

March 8th, 2010 § 0 comments

Reach gitweb at a subdirectory, i.e. “http://moosechips.com/gitweb”. The gitweb README and INSTALL files come with instructions on setting up access to your root web directory, but chances are you’re already using that for your homepage. Here’s the setup for installing to a subdirectory. (This worked for me with git-1.7.0.1)

Install git.

wget http://kernel.org/pub/software/scm/git/git-1.7.0.2.tar.bz2
tar xvfj git-1.7.0.2.tar.bz2
cd git-1.7.0.2.tar.bz2
make prefix=/usr/local all doc info
sudo make prefix=/usr/local install install-doc install-html install-info

Install gitweb to /var/www/gitweb.

make prefix=/usr/local gitweb/gitweb.cgi
sudo mkdir /var/www/gitweb
sudo cp gitweb/git* /var/www/gitweb

Create a file /var/www/gitweb/gitweb_config

# use absolute paths
$logo="/gitweb/gitlogo.png";
$stylesheet="/gitweb/gitweb.css";
$favicon = "/gitweb/git-favicon.png";
# enable human readable URLs
$feature{'pathinfo'}{'default'} = [1];

Add some lines to your httpd.conf

# Allow gitweb to be accessed at
# server.address.com/gitweb
Alias /gitweb /var/www/gitweb
# Files are actually in /var/www/gitweb
<Directory /var/www/gitweb>
# Enable CGI's
    Options ExecCGI Indexes FollowSymLinks
    AddHandler cgi-script cgi
 
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
    AllowOverride All
 
# Controls who can get stuff from this server.
    Order allow,deny
    Allow from all
 
# Use the gitweb.cgi interface by default
    DirectoryIndex gitweb.cgi
 
# Rewrite addresses
    RewriteEngine On
# Tell Apache that addresses are in the /gitweb subfolder
    RewriteBase /gitweb
# If the address is an actual file (e.g. /gitweb/gitweb.css)
# keep the address
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
# Else, pass the address path to gitweb.cgi
    RewriteRule ^.* gitweb.cgi/$0 [L,PT]
</Directory>

Restart your server.

sudo /etc/init.d/httpd restart

Reference:
Getting redirects to work in Apache for Gitweb