In this article I want to show you how to install and setup gitweb on Ubuntu 9.10 server. This should also work the same way on Ubuntu Desktop edition.
First of all install the deb package like:
sudo apt-get install gitweb
Second create a new folder in /var/www and change into that directory like:
sudo mkdir /var/www/gitweb cd /var/www/gitweb
Third, create a softlink to the /var/www/gitweb folder from where the css and the pics of gitweb originally do reside:
sudo ln -s /usr/share/gitweb/* .
Now you have all things linked to the right place. if gitweb comes in a new version, all content remains linked and all new content is automagically linked, too.
Good, now we need to modify the apache.conf. This must happen only if you do not have already this line enabled in apache.conf:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
So if this line isn’t in your apache.conf, then add this line and another one like:
sudo nano /etc/apache2/apache.conf ##add the following two lines: ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ Include /etc/gitweb/apache.conf
Next we need to create a folder in /etc namely “gitweb” and add the apache.conf for gitweb there. I always do it this way since currently I do not use vhost and subdomains and this way it just seems cleaner to me.
You can of course create the apache.config in every other place you want (in a vhost ie.). Just make sure when you include the file in /etc/apache2/apache.conf like we did above, that the paths must be correct.
Ok now lets create the folder first:
sudo mkdir /etc/gitweb
Then we add a file namely apache.conf in it like:
sudo nano /etc/gitweb/apache.conf
And we add the following code in it:
<directory /var/www/gitweb> Options Indexes FollowSymlinks ExecCGI DirectoryIndex /cgi-bin/gitweb.cgi AllowOverride All </directory>
Save the file. Then we need to configure the last file, namely gitweb.conf:
sudo nano /etc/gitweb.conf
There you enter the following code:
$projectroot = "/PATH/TO/GIT/REPOSITORIES/"; # directory to use for temp files $git_temp = "/tmp"; # target of the home link on top of all pages #$home_link = $my_uri || "/"; # html text to include at home page $home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. $projects_list = $projectroot; # stylesheet to use # I took off the prefix / of the following path to put these files inside gitweb directory directly $stylesheet = "gitweb.css"; # logo to use $logo = "git-logo.png"; # the ‘favicon’ $favicon = "git-favicon.png";
Where /PATH/TO/GIT/REPOSITORIES/ of course should be replaced by the path to your git repositories, which must be readable for the user that apache process is running!!
Last thing: restart the server like:
sudo /etc/init.d/apache2 restart
…and you should be done and gitweb now should be working and available on http://localhost/gitweb.
Comments and Suggestions are welcome!!
http://gideontsang.wordpress.com

Hey thanks for the great post. I did all the steps but I am getting a cannot access /localhost/gitweb error. Any ideas on where to look?
[...] adds in /etc/apache2/conf.d/gitweb, so there’s no other files to edit (unlike what blog1, blog2, or blog3 [...]
I followed your guide but I keep on getting this error when I try to access it.
Forbidden
You don’t have permission to access /gitweb/ on this server.
I set it up remotely via ssh and am trying to access it from my public webpage. Any ideas? I’m assuming it has something to do with the privilages in apache but I’m not quite sure what. Thanks!
Hi Yusuf!
Im glad that my tutorial worked for you!
To your question: to be honest, there are so many ways where you could add this.
For an apache vhost ie. if you would like to access gitweb like http://gitweb.mahdiyusuf.com you could create that file here: /etc/apache2/sites-available/gitweb. After creating it you need to enable the page like: “a2ensite gitweb”. This command will softlink /etc/apache2/sites-available/gitweb to /etc/apache2/sites-enabled/gitweb. After a restart of apache you should be able to access gitweb via http://gitweb.mahdiyusuf.com.
In any other case ie: http://servername/gitweb you can add this file wherever you want. As far as I have seen the “convention” would be indeed /etc/PROGRAMNAME/apache.conf
You probably want to read up about vhosts, if you like solution 1 more, since there are a few things you might need to add though. Please rad the apache docs, since this might not be that trivial at all.
best
martin
I was wondering about the setup where you create `sudo nano /etc/gitweb/apache.conf` and added the directory. Where else could I put that? isn’t there a place for available sites?
Could you go into further detail explaining that set your guide worked successfully though! Nice write up!
Hi cliff!
Yes of course! ‘Alias /gitweb /var/www/gitweb’ is not needed since we already have (soft) linked the whole stuff into ‘/var/www/’.
Thx for pointing that out. I’ll change this in the post.
regards
Martin
why do you need the ‘Alias /gitweb /var/www/gitweb’ line? Don’t you already have everything linked in to /var/www/gitweb already? In other words, doesn’t having stuff in /var/www/gitweb already show up at http://servername/gitweb?