It was a long time since my last post. Unfortunately, I was too busy with my employer’s project to write anything enough interesting to post here. I wrote some drafts, but they stay still as drafts to this day..

Intro

Recently I had some thoughts about creating my own web-accessible git repository, so I can have backup of some of my scripts and have them easily clone on other computers if I need to. I configured gitweb for this. You can see how it’s working on my repository page. This post is about how to make gitweb working on shared hosting.

Things you will need

  • access your server’s filesystem (ssh, ftp, anything to upload and manipulate files)
  • perl (because gitweb is written in perl)
  • mod_perl (to run perl on server)

Steps

Download git source code

  • using browser, wget or something other, download code from: http://git-scm.com/downloads
  • or… using git on popular social git website, clone git’s repository (^_^):
  git clone git@github.com:git/git.git

Configure

Go to the gitweb directory in your downloaded git code.

  cd git/gitweb

You can now configure gitweb by passing appropriate arguments to make. You can too configure it later in separate file like me. More info about configuration during build time you will find in INSTALL file.

Invoke make.

  make

After that file gitweb.cgi should now exists in your gitweb directory. We are especially interested in this file and the static subdirectory. Upload both of them on the server.

Upload gitweb on your server

Copy gitweb.cgi to the cgi-bin directory (there should be one in public_html). Static dir should go whenever you want, but remember that it should be still accessible from web. Example file hierarchy:

./public_html:
  cgi-bin/gitweb.cgi
  static

We copied gitweb script to the cgi-bin directory, because most probably apache is configured on your server to execute files from this place. Not just read. If it will not work, add to your .htaccess file: AddHandler cgi-script .cgi So apache will recognize it properly.

For automatically executing gitweb on index page, you can now:

  • change default directory index
  • link gitweb.cgi as index.cgi
  • rename gitweb.cgi to index.cgi

Runtime configuration

By default when you call gitweb.cgi, it searches in the same directory for: gitweb_config.perl file. Create this file and add following lines:

$projectroot = "/absolute/path/to/your/git/repos";
$GIT         = "/git/executable/on/server";

So example file will look like this:

$projectroot = "/home/rafal/repos";
$GIT         = "/usr/bin/git";

There are many more variables to override. All of them you can find in README file. Notice that $projectroot doesn’t have to point to publicly available directory.

Additionally, if you moved static to some other directory, renamed it, or changed file names inside, you should take a closer look on following variables in README:

  • @stylesheets
  • $stylesheet
  • $logo
  • $favicon
  • $javascript By setting above variables you can point back to correct files. You can also just replace defaults with any custom ones.

Outro

Probably if you read this text, you will be interested in creating remote repositories on server. I’ll write about it later in separate post, trying to deeply explain everything, so stay tuned.