Monday, January 31, 2011

Installing git-web on a java web server

Installing git-web on a java web server such as tomcat or jetty is pretty simple. All java web-servers have the capability to run cgi scripts such as git-web.

The difficult part of installing git-web is setting up all the configuration.

First, install git-web using your linux installation tool such as yast, yum, rpm, etc. Your install will assume you will use the apache web server.

Now for the hard part. Every linux distro installs the files in different locations. Here is where my files are installed:
The git-web config file:
/etc/apache2/conf.d/gitweb.conf (This tells git-web where your repositories are)
The git-web install directory:
/usr/share/git-web (The git-web cgi script and web files)

The next step is to get git-web working. There are a ton of tutorials out there. Most of them are pretty bad. I would just open up the gitweb.cgi file in a text editor and edit the parameters.

You will probably want to change the $projectroot variable to point to your git repository location.

Once you get git-web working, you are ready to install it in your java web server.

First, create a war directory (mine is called git-web) and move the git-web files to these locations:


Next, create the web.xml file in the WEB-INF directory. It should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi-bin</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/gitweb.cgi</url-pattern>
</servlet-mapping>
</web-app>

Voila! Install this war location on your java web server and git-web is ready to go: