Home Git Server =============== I'm a recent convert to [git][git] and have been using [gitosis][gitosis] to manage my private repositories. This combination works great, but sometimes I want an easy way browsing through my repositories without using a command line. While [gitweb][gitweb] makes this easy, it's not entirely trivial on how to combine it with [gitosis][gitosis]. To add even more frustration to the mix, I already run Apache for some other development work, so I can't just run `lighttpd`. I don't want to modify the permissions on my repositories, so just changing the ownership to `www-data` or giving world read and execute won't do. Also, I'm not concerned about having an open website of my repositories. My development server is firewalled from the outside world. The only exception to this is the SSH port, which means I can still use [gitosis][gitosis] from the outside world in a secure way. Credits ------- A lot of the information below was in the [gitosis tree][gitosis-tree], but either I couldn't get it to work or it didn't fit my needs completely. This is my interpretation of the instructions I read. Thanks to [Tommi Virtanen][tv] for the jumping off point. Prerequisites ------------ I'm going to assume that you already have [gitosis][gitosis] up and running under the `git` user. I've used [this][gitosis-setup] setup almost verbatim. Also, my server is running on Ubuntu Hardy Heron. If you're using something, you will have to adjust appropriately. Make Gitosis Do Some Of The Dirty Work -------------------------------------- [Gitosis][gitosis] already does some of the heavy lifting for you. By adding a simple setting to your `gitosis.conf` file, [gitosis][gitosis] will specify the repositories to publish via [gitweb][gitweb], as well as set up some descriptions for each project. Enter your `gitosis-admin` directory and edit `gitosis.conf`. If you haven't done so already, add a repository entry for each of the repositories you want visible on your web server. [repo my-project] description = The Best Project in the World owner = Joe Schmoe There is one more setting you need, but it can go in one of two places. If you just want every repository to be visible, add the following line to the global `gitosis` section. Otherwise, for each repository you want visible, add the following. gitweb = yes Commit your changes. Serve Your Repositories With Lighttpd ------------------------------------- Lighttpd is the perfect solution if you need a simple web server running as an unprivileged user. On your server, run the following, which will install lighttpd and then force it to not start by default. You may see an error about a port already in use. You can ignore it. $ sudo apt-get install lighttpd gitweb $ sudo update-rc.d -f lighttpd remove Now lets set up a framework for launching lighttpd just for [gitweb][gitweb]. First, you will want to change to the `git` user. Be warned, the `git` user doesn't use `bash` as its default shell, so you might lose some of your shortcuts that you are used to. $ sudo su - git Now we need to create a couple of directories to house our set up. Once for configurations, one for scripts and another one for lighttpd to use. $ mkdir etc bin www Lighttpd needs a custom configuration file to run [gitweb][gitweb]. Edit the `etc/lighttpd-gitweb.conf` file and add the following: server.port = 5000 server.document-root = "/home/git/www" server.modules += ( "mod_cgi", "mod_setenv", "mod_redirect", "mod_alias", ) ## mimetype mapping include_shell "/usr/share/lighttpd/create-mime.assign.pl" url.redirect += ( "^$" => "/", ) alias.url += ( "/gitweb.css" => "/var/www/gitweb.css", "/git-logo.png" => "/var/www/git-logo.png", "/git-favicon.png" => "/var/www/git-favicon.png", "/" => "/usr/lib/cgi-bin/gitweb.cgi", ) setenv.add-environment = ( "GITWEB_CONFIG" => "/home/git/etc/gitweb.conf", ) cgi.assign = ( ".cgi" => "/usr/bin/perl" ) I'm using port 5000 to run [gitweb][gitweb] on. You can change this to what ever you desire. Also note that we are pointing to a custom `gitweb.conf` file. This config file is what will point to all of the work that [gitosis][gitosis] did for us. Edit `etc/gitweb.conf` and add the following: do "/etc/gitweb.conf" if -e "/etc/gitweb.conf"; $projects_list = "/home/git/gitosis/projects.list"; $projectroot = "/home/git/repositories"; $export_ok = ""; $strict_export = "true"; @git_base_url_list = ('git://git'); In a nutshell, this config file loads your systems `gitweb.conf` file, reads the list of repositories from [gitosis][gitosis], points to the location of the repositories and serves them all up. Lastly, we need to create a start up script for lighttpd. Edit the `bin/launch-gitweb` file and add the following: #!/bin/sh /usr/sbin/lighttpd -D -f /home/git/etc/lighttpd-gitweb.conf Don't forget to make this executable. $ chmod +x bin/launch-gitweb At this point, you can test your progress. Still as the `git` user, launch the lighttpd process. $ bin/launch-gitweb No point your browser to port 5000 of your [git][git] server and you should see your repositories. If everything is working, kill lighttpd. Exit back to a user that has `sudo` privileges. We are going to create a script to launch this lighttpd session automatically when the system starts. Edit the file `/etc/event.d/local-git-web` and add the following. start on startup stop on shutdown exec su --command="/home/git/bin/launch-gitweb" git respawn To make sure this works, run the following. If you access the site like you did above, everything is set up correctly. $ sudo initctl start local-git-web Making Apache Point to Lighttpd ------------------------------- Lastly, since typing in the port above is so difficult, we are going to have our existing Apache server point to lighttpd using a VirtualHost. I have a DNS record of `git` pointed to my development server, so I created `/etc/apache2/sites-available/git` that looks like the following: ServerName git ServerAlias git.example.com ProxyRequests Off ProxyPreserveHost On ProxyPass / http://localhost:5000/ ProxyPassReverse / http://localhost:5000/ Also, you need to modify how proxying works in Apache. Edit the `/etc/apache2/mods-available/proxy.conf` file. You will need to make two changes. First, change `ProxyRequests Off` to `ProxyRequests On`. Next, uncomment the `Allow` statement and change it to allow your subnet. Allow 192.168.100.0/24 We need to make a couple other changes to make this all work. $ sudo a2enmod proxy proxy_connect proxy_http $ sudo a2ensite git $ sudo invoke-rc.d apache2 force-reload You should now be able to hit your repositories without specifying a port. How convenient! [git]: http://git.or.cz/ "Fast Version Control System" [gitosis]: http://eagain.net/gitweb/?p=gitosis.git;a=summary "Software for Hosting Git Repositories" [gitosis-setup]: http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way "Hosting Git repositories, The Easy (and Secure) Way" [gitosis-tree]: http://eagain.net/gitweb/?p=gitosis.git;a=tree "Gitosis Tree" [gitweb]: http://git.or.cz/gitwiki/Gitweb "Git Web Interface" [tv]: http://eagain.net/blog/ "Tv's cobweb"