5 Jul 2011

GITWEB

Once we have the GIT server up and running with the repository structures in place, we need to explore more about GITWEB, so as to make browsing of repositories easier. This post will provide pointers related to setting up GITWEB and its configuration.

 

What is GITWEB??

  • 'Gitweb' is a Git web interface, the one working on http://www.kernel.org/git
  • It is written in Perl, and can be used as a CGI script, or as a mod_perl legacy script
  • It allows browsing a git repository (or a set of git repositories) using a web browser.
  • Using gitweb we can browse directory trees at arbitrary revisions, view contents of files, see log or examine commits, commit messages and changes made by a given commit.
  • We can search for commits by an author, added to repository by a comitter, commit with commit message (commit description) which includes some text.
GITWEB CONFIGURATION
Install Apache
First, you need to ensure apache2 is installed. Check to see if you have an /etc/apache2 folder. If you do, you should be okay. If you don’t, you need to install it.  sudo apt-get install apache2
Once you have that installed and the daemon is restarted, type the ip address in the browser and you should something like “It Works” 

Issues related to Apache
There can be lot of issues related to apache configuration, some are listed below:-
There may be a firewall running on your server, and it might be blocking traffic to the standard web server ports, port 80 (for regular connections) and port 443 (for secure connections).
Check the current firewall rule:-
sudo  /sbin/iptables –L
IP table rules to open the ports
sudo /sbin/iptables -I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo /sbin/iptables -I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
sudo /sbin/iptables -I INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo /sbin/iptables -I OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT



Logs
Apache logs are stored under:- /var/log/apache2     

Test the server
If you navigate to your server's IP address in a web browser: http://<ip address>
You should see a default page telling you apache is working
INSTALL GITWEB
sudo apt-get install gitweb
This will install gitweb into /var/www/gitweb, create a conf file at /etc/gitweb.conf, and add three files to /usr/share/gitweb (git-favicon.png, git-logo.png, gitweb.css).
If for some reason, the /var/www/gitweb folder is not created, you can clone the git source (git clone git://git.kernel.org/pub/scm/git/git.git) and then just copy the git/gitweb folder to /var/www/gitweb

cp –R git/gitweb /var/www/
You only need to edit the $projectroot variable in the /etc/gitweb.conf to point to your repositories folder:

/etc/gitweb.conf
=============================== 
# path to git projects (<project>.git)
$projectroot = "/project";
# 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
$stylesheet = "/gitweb/gitweb.css";
# logo to use
$logo = "/gitweb/git-logo.png";
# the 'favicon'
$favicon = "/gitweb/git-favicon.png";
#enable human readable URLs
$feature{'pathinfo'}{'default'} = [1];
===============================
Since Ubuntu includes the entire /etc/apache2/conf.d directory, so we just added the following information into /etc/apach2/conf.d/gitweb:-

 /etc/apache2/conf.d/gitweb.conf
===============================
AddHandler cgi-script .cgi
#</Directory>
ServerName hostname1
<Directory /var/www/gitweb>
RewriteRule ^/gitweb/([a-zA-Z0-9_\-]+\.git)/?(\?.*)?$ /cgi-bin/gitweb.cgi/$1 [L,PT]
Options Indexes FollowSymlinks ExecCGI
DirectoryIndex /cgi-bin/gitweb.cgi
AllowOverride None
</Directory>

 /etc/apache2/sites-enabled/000-defaul
===============================
 
Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

ScriptAlias /git "/usr/lib/cgi-bin/gitweb.cgi"
        <Directory "/var/www/gitweb">
                Options Indexes FollowSymLinks ExecCGI
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
===============================

Restart Apache to make sure everything works....

Congratulation, the gitweb is up and running on your system now. Hope you find this article useful, If there are any issues or concerns feel free to share your feedback.

5 comments:

  1. Missed out to provide 1 info:-

    If you get such error while restarting apache:-

    ===
    sudo /etc/init.d/apache2 restart
    Syntax error on line 12 of /etc/apache2/conf.d/gitweb.conf:
    Invalid command 'RewriteRule', perhaps misspelled or defined by a module not included in the server configuration
    Action 'configtest' failed.
    The Apache error log may have more information.
    ...fail!
    ====

    this is because the rewrite module isn't enabled by default. This will enable it:-
    ==========
    sudo a2enmod rewrite
    Enabling module rewrite.
    Run '/etc/init.d/apache2 restart' to activate new configuration!
    ==========

    ReplyDelete
  2. Hi Sahil, I am getting the following error, after installing the apache and try my ip in the browser

    Forbidden

    You don't have permission to access / on this server.

    Apache/2.2.16 (Ubuntu) Server at localhost Port 80

    ReplyDelete
  3. After installing the gitweb, i dint get the folder /var/www/gitweb , do we need to manually create it?, but i have got all other fle you have specified.

    ReplyDelete
  4. Thanks Sugnan for the comments.

    Coming to first comment:-
    Have you tried IP tables, it could be the cause related to port 80...

    try this:-
    ====
    sudo /sbin/iptables -I INPUT -p tcp --dport 80 -m state --state NEW, ESTABLISHED -j ACCEPT
    sudo /sbin/iptables -I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
    sudo /sbin/iptables -I INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
    sudo /sbin/iptables -I OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
    =====

    ReplyDelete
  5. Regarding /var/www/gitweb

    If for some reason, the /var/www/gitweb folder is not created, you can clone the git source (git clone git://git.kernel.org/pub/scm/git/git.git) and then just copy the git/gitweb folder to /var/www/gitweb


    cp –r git/gitweb /var/www/

    ReplyDelete