Christopher Jackson's

hacks, thoughts, and utter ramblings.

Setting Up Gitweb on Ubuntu Server(10.04) Using Apache2(w/ Vhosts)

Lets say you want to set up gitweb on your server and reach it from git.yoursite.com. Here is what you will need to do. This tutorial assumes that you already have installed apache2 and git using apt-get install.

First you need to install gitweb by running the following command:
1
sudo apt-get install gitweb
Next, you will need to create a virtual host under apache2. My preferred method for doing this is as follows:
1
2
3
sudo touch /etc/apache2/sites-available/git.yoursite.com
cd /etc/apache2/sites-enabled
sudo ln -s ../sites-available/git.yoursite.com xxx-git

Replace the xxx with three integers or you can name the file anything you want. The only thing to be careful about here is apache will load the first file in the directory as the main site. The way to ensure a certain site is loaded before others is to maintain the naming schema of having 3 digits in the front of the file name. You will notice this by the presence of the default site /etc/apache2/sites-enabled/000-default.

Now you will need to fill in the details for the virtual host by copying the following text into file:

/etc/apache2/sites-available/git.yoursite.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<VirtualHost *:80>
	ServerName git.yoursite.com
	ServerAlias www.git.yoursite.com
	DocumentRoot "/usr/share/gitweb"

	<Directory /usr/share/gitweb>
		Options FollowSymLinks +ExecCGI
		AddHandler cgi-script .cgi
 		#Allow from all
		#AllowOverride all
		#Order allow,deny
	</Directory>

	<Directory /var/cache/git>
		#Allow from all
	</Directory>
	#RewriteLog /var/log/apache2/rewritegitweb.log
	#RewriteLogLevel 9
	#ErrorLog /var/log/apache2/gitweb.log
</VirtualHost>
The directives that are commented out above are not needed. You may find the log ones at the bottom useful if you’re having issues after the installation. The generated logs make it easier to track down what is going wrong.

Now all you have to do is restart apache
1
sudo apachectl graceful

You should now be able to hit http://git.yoursite.com and see gitweb. Enjoy!