Tuesday, April 29, 2008

gitweb + apache + gentoo

This is meant as a quick tutorial to get gitweb up and running on gentoo with apache as the web server.


since git version 1.4, gitweb is bundled with git and can be installed by building with the cgi and perl use flags.

add the following to your package.use file:


dev-util/git perl cgi

emerge all the required packages...

> sudo emerge dev-util/git
> sudo emerge apache

install a copy of gitweb to apache's cgi-bin directory

> sudo cp -r /usr/share/git/gitweb /var/www/localhost/cgi-bin
> sudo chown -R apache:apache /var/www/localhost/cgi-bin/gitweb

note: change the 'apache' user and group to whatever you have apache configured to run as.


create a new virtual host file in your apache vhosts.d directory to be used for accessing gitweb.


<VirtualHost *:80>
     ServerName git.mydomain.com
     DocumentRoot /var/www/localhost/cgi-bin/gitweb 
     <Directory /var/www/localhost/cgi-bin/gitweb>
          Allow from all
          AllowOverride all
          Order allow,deny
          Options ExecCGI
          <Files gitweb.cgi>
               SetHandler cgi-script
     DirectoryIndex gitweb.cgi
     SetEnv  GITWEB_CONFIG  /etc/gitweb.conf

note: if you are just using this for localhost and/or you are not setting this up as a subdomain you can just overwrite the default VirtualHost defined in 00_default_vhost.conf with the above and change 'ServerName' to localhost


create and edit your gitweb configuration file to point to the root of your projects directory. (/var/git in my case)


$projectroot = '/var/git';

note: additional configuration options can be found here: http://repo.or.cz

> cd /var/git
> mkdir test.git
> cd test.git
> git --bare init
> echo "this is a test" > description

push a project to the gitweb repo

> git push phil@mydomain.com:/var/git/test.git

note: if there is a permissions issue check the test.git repo permissions and ensure you have write access.

if you need more security or are looking to manage access and permissions without using system accounts you might want to check out gitosis for the shared repo.

> sudo /etc/init.d/apache2 start

point your browser to the address you put in for the vhost config and you should be in business.

if your projects are not being listed in gitweb, try adding your apache user to the git group or whatever group the project dir belongs to. also try this if you updated git and your projects are now showing "no commits". i believe the default group permissions for a shared repo were changed/fixed. i noticed this at v. but didn't track down the actual commit.

if the owner names for the projects are not showing up you can add a name through the usermod command.

> sudo usermod -c "phil sergi" phil


Donnie Berkholz said...

The newer versions of git install gitweb with USE="perl cgi" -- it goes into /usr/share/git/gitweb, so you need to add that directory to apache instead of installing the separate gitweb package.

Phil said...

this is exactly what the gitweb ebuild does, i just feel it is a cleaner install.

Donnie Berkholz said...

Sure, if it's current... hopefully gitweb hasn't changed between and

Phil said...

the gitweb ebuild is now hard masked and i updated the post to just use git now.

Mike said...

Thanks Phil! That's exactly what I was looking for.

Remz-Jay said...

Don't forget to mention that (nowadays?) you need to set a USE flag to install a CGI handler for Apache. By default it will just echo your CGI script's content.

To do this:
edit /etc/make.conf
Add "cgid" or "cgi" (depending on your MPM) to the APACHE2_MODULES= directive.

'emerge apache' to rebuild
'/etc/init.d/apache2 restart' to activate the changes, enjoy!