Setting up Gitorious on your own server

Gitorious logo

Gitorious is an open source Rails application for managing your projects: Git repositories, wikis, timeline and more. Not identical to, but not completely unlike GitHub. Being open source means you can set up your own Gitorious, even in private mode and host all your company's projects. In this article I'll show you how to get it running.

A better way to install Gitorious

Much time has passed since this guide was written. This guide is no longer relevant, but I will keep around for historic reference. Please do not follow it. For your convenience, getgitorious.com now provides both pre-built Gitorious virtual machines as well as an automated installer. If you still want to roll the manual way, the official repository now has updated recipes for setting Gitorious up for development work for Ubuntu and Enterprise Linux.

The guide

It bears repeating: This guide is around for historic reference only, please do not use it.

I am going to guide you through installing Gitorious on an Ubuntu box. Instructions should most likely work equally well for Debian boxes. For other OS flavours, adjust package manager and paths accordingly.

Gitorious comes with great documentation. This guide is mainly based on what ships with Gitorious. However, there are some aspects of the docs that are a bit dated, and in some cases not complete. The following howto was compiled on a blank Ubuntu 9.04 installation, and should get you all the way there. I intend to share these instructions back into the official documentation.

Update 2011-02-15: Several minor changes from Dominic Sayers that makes the guide work equally well for Ubuntu 10.10. A revised version of this document will appear on the Gitorious wiki shortly.

To verify that these instructions are indeed correct I worked through the guide on a clean Ubuntu install. From start to finish I spent roughly an hour. I did this twice: using Ruby 1.8 and using Ruby 1.9.

Instead of providing you with one giant apt-get install command, I've grouped them by libraries in an attempt to give you a better understanding of which components Gitorious sits on.

Install Git and system essentials

sudo apt-get install -y git-core git-svn
sudo apt-get install -y apg build-essential libpcre3 libpcre3-dev sendmail \
make zlib1g zlib1g-dev ssh

Ruby and required libraries

Gitorious runs on a variety of Rubys. You'll have to choose whichever suits you. I'm going to show you how to get started with 1.8.7 from apt, Ruby Enterprise Edition from a .deb package, and Ruby 1.9 from source. We'll symlink whichever binary we end up with as /usr/bin/ruby, and then you can follow along with either one. If you already have Ruby on your system, but want to roll Gitorious with another Ruby make sure you use e.g. ruby1.9 and gem1.9 in the following snippets.

Ruby 1.8 from Apt

sudo apt-get install -y ruby1.8 libbluecloth-ruby libopenssl-ruby1.8 ruby1.8-dev \
    ri rdoc irb
sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby

Ruby Enterprise Edition from .deb package

Ruby Enterprise Edition is a server oriented memory efficient version of Ruby 1.8.6 from Phusion, the guys behind Passenger. We'll get the .deb package from Phusion:

cd ~/src
wget http://rubyforge.org/frs/download.php/58679/ruby-enterprise_1.8.6-20090610_i386.deb
sudo dpkg -i ruby-enterprise_1.8.6-20090610-i386.deb

Append these lines to the bottom of to /etc/profile ( sudo emacs /etc/profile):

export PATH=/opt/ruby-enterprise/bin:$PATH
export LD_LIBRARY_PATH="/usr/local/lib"
export LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib"

Prepend /usr/local/lib to /etc/ld.so.conf so the file reads:

/usr/local/lib
include ld.so.conf.d/*.conf

Then run

sudo su
source /etc/profile
sudo ldconfig

Ruby 1.9 from source

Instructions found here, and updated.

Required packages:

sudo apt-get -y install libc6-dev libssl-dev libmysql++-dev \
    libsqlite3-dev libreadline5-dev

Get the latest version of Ruby 1.9.1 from here. Currently patchlevel 243 is the most recent version:

mkdir ~/src
cd ~/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz
tar xvzf ruby-1.9.1-p243.tar.gz
cd ruby-1.9.1-p243
./configure --prefix=/usr/local
make && sudo make install

MySQL bindings

cd ~/src
wget http://rubyforge.org/frs/download.php/51087/mysql-ruby-2.8.1.tar.gz
tar xzvf mysql-ruby-2.8.1.tar.gz
cd mysql-ruby-2.8.1
sudo ruby extconf.rb
make && sudo make install

RubyGems

Skip this section if you're on Ruby 1.9 - it bundles RubyGems.

If you're using Ruby 1.8 (from apt, or REE), get RubyGems from source, do not go with the apt-provided RubyGems. You will need RubyGems > 1.3.5 and < 1.5.0 (...). You can select your preferred version from this page, or just go with my recommendation, 1.4.2:

cd ~/
mkdir src
cd src
wget http://rubyforge.org/frs/download.php/73882/rubygems-1.4.2.tgz
tar xvzf rubygems-1.4.2.tgz
cd rubygems-1.4.2
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Keep the ~/src directory - we'll use it to compile a few other libraries as well.

Common libraries

Regardless of your Ruby version, you'll want these tools:

sudo apt-get install -y libonig-dev libyaml-dev geoip-bin \
    libgeoip-dev libgeoip1

A note from August Flatby: Turns out libyaml-dev is not available on Ubuntu JeOS 8.04. Not to worry though, you don't need the package to get Gitorious running on JeOS 8.04.

RMagick

sudo apt-get install -y imagemagick libmagickwand-dev

Another note from August Flatby: Ubuntu JeOS 8.04 does not have a libmagickwand-dev either, install libmagick9-dev instead.

Install MySQL

Gitorious documentation says that "Gitorious should be free of MySQL-isms". I haven't tested with anything else, but if you prefer PostgreSQL or something else, go ahead. It should work like you're used to with Rails.

sudo apt-get install -y mysql-client-5.0 mysql-server-5.0 libmysqlclient15-dev

Get Sphinx and Ultrasphinx

If you want to be able to search your Gitorious, you'll need Sphinx.

cd ~/src
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8.tar.gz
tar xvfz sphinx-0.9.8.tar.gz
cd sphinx-0.9.8
./configure
make && sudo make install

Download and install ActiveMQ

Gitorious uses the ActiveMessaging framework to talk to a message queue that handles most of it's background processing that is out of scope for a simple web request. Such tasks include adding SSH keys and creating projects and repositories. You should be able to use a variety of messaging systems, but we'll setup ActiveMQ and the Stomp connector, as is recommended by the Gitorious documentation.

You'll find the latest ActiveMQ here. At the time of writing, the latest release is 5.2.0.

sudo apt-get install -y uuid uuid-dev openjdk-6-jre
cd ~/src
wget http://www.powertech.no/apache/dist/activemq/apache-activemq/5.2.0/apache-activemq-5.2.0-bin.tar.gz
sudo tar xzvf apache-activemq-5.2.0-bin.tar.gz  -C /usr/local/
sudo sh -c 'echo "export ACTIVEMQ_HOME=/usr/local/apache-activemq-5.2.0" \
    >> /etc/activemq.conf'
sudo sh -c 'echo "export JAVA_HOME=/usr/" >> /etc/activemq.conf'
sudo adduser --system --no-create-home activemq
sudo chown -R activemq /usr/local/apache-activemq-5.2.0/data

Turn off the default multicasting activemq does, or other brokers on the same network will receive your queue items. Edit /usr/local/apache-activemq-5.2.0/conf/activemq.xml as root:

sudo emacs /usr/local/apache-activemq-5.2.0/conf/activemq.xml

Find the networkConnectors configuration and change it to look like:

<networkConnectors>
    <!-- by default just auto discover the other brokers -->
    <!-- <networkConnector name="default-nc" uri="multicast://default"/> -->
    <!-- Example of a static configuration: -->
    <networkConnector name="localhost" uri="static://(tcp://127.0.0.1:61616)"/>
</networkConnectors>

In newer versions of ActiveMQ this block doesn't exist, instead add this one:

<transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>

Then get this handy init script:

cd ~/src
wget http://launchpadlibrarian.net/15645459/activemq
sudo mv activemq /etc/init.d/activemq
sudo chmod +x /etc/init.d/activemq

And add it to the default run levels if you want it to boot with your machine:

update-rc.d activemq defaults

Memcache

Installing memcache is not strictly required to run Gitorious, but it's highly recommended for performance:

sudo apt-get install -y memcached
sudo update-rc.d memcached defaults

Apache

This part is optional. If you prefer some other production environment, go with your weapons of choice. If you do go with something else, be sure to get some of the finer points on users and permissions, though, or else you might find your Gitorious isn't working correctly.

sudo apt-get install -y apache2

We'll run Gitorious with mongrel while setting up, so we'll defer installation of Passenger for now.

Get the Gitorious source code

We're going to add a gitorious group that we'll share the source with. Everyone that needs to work on the Gitorious code can be added to this group to gain access.

sudo groupadd gitorious
sudo usermod -a -G gitorious christian

christian (username, we're not discussing religion here) is me, adjust accordingly. I've had trouble with newly created/added groups before. To be sure everything works as intended, be sure to log in again. You can do this simply by issuing su christian (substitute your own username).

Now create a base directory to hold Gitorious, the logs and Apache configuration files.

sudo mkdir -p /var/www/git.myserver.com
sudo chown christian:gitorious /var/www/git.myserver.com
sudo chmod -R g+sw /var/www/git.myserver.com

This will set the setgid bit, ensuring the gitorious group follows new files and directories inside /var/www/git.myserver.com

Now create a home for Gitorious:

cd /var/www/git.myserver.com
mkdir log
mkdir conf
git clone git://gitorious.org/gitorious/mainline.git gitorious
sudo ln -s /var/www/git.myserver.com/gitorious/script/gitorious /usr/local/bin/gitorious
cd gitorious/
rm public/.htaccess
mkdir -p tmp/pids
sudo chmod ug+x script/*
sudo chmod -R g+w config/ log/ public/ tmp/

/var/www/git.myserver.com/conf and /var/www/git.myserver.com/log are for Apache configuration and log files. We'll create those later.

Copy executables

Gitorious ships with ready to use git-ultrasphinx and git-daemon scripts. Be aware that the git-daemon script has hardcoded paths to both Ruby Enterprise Edition and Gitorious. Pop open git-daemon and set correct paths to the Ruby you want to use (stick with REE if you installed it earlier) and your Gitorious installation. These are the lines you need to see (lines 16 and 18 at the time of writing):

# in /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-daemon
GIT_DAEMON="/opt/ruby-enterprise/bin/ruby \
    /var/www/git.myserver.com/gitorious/script/git-daemon -d"
PID_FILE=/var/www/git.myserver.com/gitorious/log/git-daemon.pid

It is tempting to "correct" the pid file location from log to tmp/pids. Resist this temptation. Doing so will cause you major frustration as you discover that indeed script/git-daemon (which is run by this script) creates the pid file in log anyway, so changing the PID_FILE will only cause the script to fail to find the pid file, thus reporting failures. Don't go there.

The git-ultrasphinx script has paths you should review, too, as seen here:

GITORIOUS_HOME="/var/www/gitorious"
RETVAL=0
START_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:start RAILS_ENV=production"
STOP_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:stop RAILS_ENV=production"
RESTART_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:restart RAILS_ENV=production"
STATUS_CMD="cd $GITORIOUS_HOME && rake ultrasphinx:daemon:status RAILS_ENV=production"
LOCK_FILE=/var/lock/git-ultrasphinx
PID_FILE=$GITORIOUS_HOME/db/sphinx/log/searchd.pid

Fix the paths, then copy the scripts to the right place

sudo ln -s \
  /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-ultrasphinx \
  /etc/init.d/git-ultrasphinx
sudo ln -s \
  /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-daemon \
  /etc/init.d/git-daemon

Now install the services

sudo chmod +x /etc/init.d/git-ultrasphinx
sudo chmod +x /etc/init.d/git-daemon
sudo update-rc.d -f git-daemon start 99 2 3 4 5 .
sudo update-rc.d -f git-ultrasphinx start 99 2 3 4 5 .

Get your Gems on!

Gitorious uses a whole bunch of gems, that are now easily managed by Bundler:

gem install bundler
cd /var/www/git.myserver.com/gitorious && bundle install

Creating a home for Git repositories

Add a git user

You'll need a user in charge of your git repositories, the git daemon and the message queue poller. Normally this user is called git, giving you git@git.myserver.com push URLs, but you may call the user whatever you like.

sudo adduser git
sudo usermod -a -G gitorious git
sudo mkdir /var/git
sudo mkdir /var/git/repositories
sudo mkdir /var/git/tarballs
sudo mkdir /var/git/tarball-work
sudo chown -R git:git /var/git

Give the user a password and so on as prompted. The Gitorious documentation recommends you to chown -R git:git on the Gitorious code, but I wouldn't recommend it as it makes working with the code a bit more cumbersome. Also, it isn't really necessary, but I'll get back to that when we try to run the whole stack.

Now, we need to login as the git user to do some work. When someone tries to push to a repository through Gitorious, the user will be looked up in the git user's ~/.ssh/authorized_keys. If the user is found here, the ssh connection is handled by the git-daemon process. We have to create this file, but Gitorious will maintain it for us.

su git
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys

Ruby Enterprise Edition

If you went with Ruby Enterprise Edition, you'll need to tell the git user to use it:

Append the following to /home/git/.bashrc ( emacs ~/.bashrc as git user):

# User specific aliases and functions
export RUBY_HOME=/opt/ruby-enterprise
export GEM_HOME=$RUBY_HOME/lib/ruby/gems/1.8/gems
export PATH=$RUBY_HOME/bin:$PATH

Adjust accordingly if you installed Ruby 1.9 and it's not the system default ruby.

Configure Gitorious and migrate database

Next up we'll configure Gitorious and create the database. We need to configure the database, the broker (for the messaging system) and Gitorious itself. If you're still logged in as 'git', log back out.

cd /var/www/git.myserver.com/gitorious
cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml
cp config/broker.yml.example config/broker.yml

Configure gitorious.yml

First, generate a huge secret key with apg:

apg -m 64

Copy this, remove newlines and keep it in your kill ring. Open the config/gitorious.yml file. I'll make a brief commentary on some properties here, and then I'll show you what my config looks like. Adjust yours accordingly. It's a good idea to configure the development environment to match your, well, development machine, and the production environment for the actual deployment server.

gitorious_host

This should match the hostname you access Gitorious with. It's important, because Gitorious will create a Site object tied to the hostname. The Site object is used to scope projects. This means that you can actually run several Gitorious sites from the same installation, keeping groups of projects detached from eachother. Could be useful if you need separate departments in a big company or the like. It also means you cannot create projects on localhost and expect to find them on git.myserver.com.

I recommend git.local for development and git.myserver.com (i.e., the site you'll be running Gitorious on) for production. For some reason, I'm unable to login if I configure the hostname to be localhost in development. Just add the git.local hostname to /etc/hosts.

gitorious_client_host and gitorious_client_port

These are the values used by script/server. However, they're also used by the git-daemon, so be sure to set these correctly, or you'll have trouble pushing.

public_mode

If you're setting up a closed Gitorious (for your company, or maybe privately for yourself), you'll want to set this to false. If you want people to be able to browse your projects without logging in, you can keep it true.

The whole deal

Here's an example configuration. The test environment is configured, too. This way we can run the tests to verify that Gitorious is working correctly.

development:
  # The session secret key (`apg -m 64` is always useful for this kinda stuff)
  cookie_secret: HievdaibAinUnfagvodEdaytsaydWivCyfreOkKiosavDovDevBatyabdabFasfa\
fedevpidPokCarWaGloicAtcajKoabmeharditMevOfPybIdthAvUrthEmceect_\
keuzCawHetweklUsFifDogazviOleickocbihoDrapuchujotvethubTejCoavra\
jojhisVacfunHegOskOchCezgochtyRacoidGod{DreujvuAworvyewnEdWolliv\
CawtouwebyurgUnEalwufnachayFlorj2QuenotThuelbOakmockedeciamveadd\
uzVoguftichcibNocBempIkbekyelmIdyoatEucciphtunsefavdercUdibtheef

  # The path where git repositories are stored. The actual (bare) repositories
  # resides in repository_base_path/#{project.slug}/#{repository.name}.git/:
  repository_base_path: "/var/git/repositories"

  # Stuff that's in the html <head>. custom stats javascript code etc
  extra_html_head_data:

  # System message that will appear on all pages if present
  system_message:

  # Port the ./script/gitorious script should use:
  gitorious_client_port: 3000

  # Host the ./script/gitorious script should use:
  gitorious_client_host: git.local

  # Host which is serving the gitorious app, eg "gitorious.org"
  gitorious_host: git.local

  # User which is running git daemon
  gitorious_user: git

  # Email spam on server errors to:
  exception_notification_emails: christianATcjohansen.no

  # Mangle visible e-mail addresses (spam protection)
  mangle_email_addresses: true

  # Enable or Disable Public Mode (true) or Private Mode (false)
  public_mode: false

  # Define your locale
  locale: en

  # Where should we store generated tarballs?
  # (should be readable by webserver, since we tell it to send the file using
  # X-Sendfile)
  archive_cache_dir: "/var/git/tarballs"
  # Which directory should we work in when we generate tarballs, before moving
  # them to the above dir?
  archive_work_dir: "/var/git/tarballs-work"

  # is it only site admins who can create new projects?
  only_site_admins_can_create_projects: true

  # Should we hide HTTP clone urls?
  hide_http_clone_urls: false

  # Is this gitorious.org? Read: should we have a very flashy homepage?
  is_gitorious_dot_org: false

production:
  cookie_secret: HievdaibAinUnfagvodEdaytsaydWivCyfreOkKiosavDovDevBatyabdabFasfa\
fedevpidPokCarWaGloicAtcajKoabmeharditMevOfPybIdthAvUrthEmceect_\
keuzCawHetweklUsFifDogazviOleickocbihoDrapuchujotvethubTejCoavra\
jojhisVacfunHegOskOchCezgochtyRacoidGod{DreujvuAworvyewnEdWolliv\
CawtouwebyurgUnEalwufnachayFlorj2QuenotThuelbOakmockedeciamveadd\
uzVoguftichcibNocBempIkbekyelmIdyoatEucciphtunsefavdercUdibtheef

  repository_base_path: "/home/git/repositories"
  extra_html_head_data:
  system_message:
  gitorious_client_port: 80
  gitorious_client_host: git.myserver.com
  gitorious_host: git.myserver.com
  gitorious_user: git
  exception_notification_emails: christianATcjohansen.no
  mangle_email_addresses: true
  public_mode: false
  locale: en
  archive_cache_dir: "/var/git/tarballs"
  archive_work_dir: "/var/git/tarballs-work"
  only_site_admins_can_create_projects: true
  hide_http_clone_urls: false
  is_gitorious_dot_org: false

test:
  cookie_secret: HievdaibAinUnfagvodEdaytsaydWivCyfreOkKiosavDovDevBatyabdabFasfa\
fedevpidPokCarWaGloicAtcajKoabmeharditMevOfPybIdthAvUrthEmceect_\
keuzCawHetweklUsFifDogazviOleickocbihoDrapuchujotvethubTejCoavra\
jojhisVacfunHegOskOchCezgochtyRacoidGod{DreujvuAworvyewnEdWolliv\
CawtouwebyurgUnEalwufnachayFlorj2QuenotThuelbOakmockedeciamveadd\
uzVoguftichcibNocBempIkbekyelmIdyoatEucciphtunsefavdercUdibtheef

  repository_base_path: "/var/git/repositories"
  extra_html_head_data:
  system_message:
  gitorious_client_port: 3000
  gitorious_client_host: localhost
  gitorious_host: localhost
  gitorious_user: git
  exception_notification_emails: christianATcjohansen.no
  mangle_email_addresses: true
  public_mode: true
  locale: en
  archive_cache_dir: "/var/git/tarballs"
  archive_work_dir: "/var/git/tarballs-work"
  only_site_admins_can_create_projects: false
  hide_http_clone_urls: false
  is_gitorious_dot_org: false

NOTE: I'm reusing the development directories for the test environment. This is assuming you're not using the development environment for anything real. If you are, you might want to isolate the test work areas as well.

Configuring broker.yml

You can check the broker configuration in conf/broker.yml, but you don't need to change anything. Wow, that was easy!

Install remaining gems and migrate database

Edit config/database.yml to your own liking, then pop open mysql and create the database and the user:

mysql -uroot -p
create database gitorious;
create database gitorious_test;
create database gitorious_dev;
grant all privileges on gitorious.* to YOURUSER@localhost \
    identified by 'YOURPASSWORD';
grant all privileges on gitorious_test.* to YOURUSER@localhost;
grant all privileges on gitorious_dev.* to YOURUSER@localhost;

If your user already exists and has create privileges (i.e., if your using root), you can do rake db:create instead of the above. I prefer to give database users as limited privileges as possible.

Note: If you see the ""undefined local variable or method `version_requirements'"" error, it probably means you're running RubyGems 1.5. Rails 2.3.5 (which Gitorious currently relies on) does not run with RubyGems 1.5. You can either downgrade RubyGems to 1.4.2 or put the following block of code between the bootstrap and initialize sections in config/environment.rb:

if Gem::VERSION >= "1.3.6" 
  module Rails
    class GemDependency
      def requirement
        r = super(r == Gem::Requirement.default) ? nil : r
      end
    end
  end
end

A hard-earned lesson on environments

In addition to file system permissions, Rails environment juggling can get you into trouble. Weird and frustrating trouble. Trust me. As we now start building the Rails app you should make sure you choose the environment you're setting up and sticking to it. Assuming you're setting up this to run Gitorious - as opposed to work on Gitorious - I'll give all the examples with the production environment.

Gitorious can trip you up if you don't pay close attention to environments: the git-daemon uses the production environment by default. However, forgetting to specify an environment will cause other scripts to use the development environment. This also goes for script/poller, which polls the queue for tasks. This fact cost me some time and earned me an antique facepalm.

The lesson is as follows: Always specify your environment to avoid confusion.

Migrating the database

With that out of the way, now we can migrate the database:

rake db:setup RAILS_ENV=production

Then, add a site administrator:

cd /var/www/git.myserver.com/gitorious
env RAILS_ENV=production ruby script/create_admin
script/console production
> user = User.first
> user.login = "christian" # Change to your desired username
> user.activate
> user.accept_terms
> user.save

You'll be prompted for credentials, and the user will be created and automagically activated. You then activate the user by hand by using script/console. Alternately, you could check your email and activate.

Get Ultrasphinx running

cd /var/www/git.myserver.com/gitorious
rake ultrasphinx:bootstrap RAILS_ENV=production

If you want to try search for development, change the RAILS_ENV above.

Permissions

The devil's in the details. Before running Gitorious, you need to get your permissions right.

The easiest way to achieve this is to run all the services using the git user:

cd /var/www/git.myserver.com/gitorious
sudo chown -R git:gitorious config/environment.rb script/poller log tmp
sudo chmod -R g+w config/environment.rb script/poller log tmp
sudo chmod ug+x script/poller

Don't forget log and tmp! If not, Gitorious will break trying to create pids and logs.

Now, run all the services:

sudo /etc/init.d/activemq start
sudo env RAILS_ENV=production /etc/init.d/git-daemon start
su git -c \
  "cd /var/www/git.myserver.com/gitorious && \
    env RAILS_ENV=production script/poller run"

Later, you can use script/poller start to run the poller in the background. For debugging, it's better to be able to follow the output. The gitorious script runs with the production environment as default, so we'll start the application in production mode. If you don't, the daemon won't find the app and pushing won't work (i.e., gitorious_client_host and gitorious_client_port needs to point to a running Gitorious instance, or the git-daemon won't be able to do it's job). Now, the exciting moment:

su git -c \
  "cd /var/www/git.myserver.com/gitorious && script/server -e production"

This should start the server successfully. Now head over to http://git.local:3000, and with any bit of luck, you didn't miss a detail and the Gitorious splash screen will great you. Log in with the user you created earlier. Head over to http://git.local:3000/~christian/keys/new (substitute your username). Now, in a shell get your public key:

cat ~/.ssh/id_rsa.pub

Copy it and paste into the textarea. If you don't have a public key, generate one:

ssh-keygen

Pasting in the key and saving it should cause Gitorious to do work via the message server. Wait a moment and refresh the page. Your key should be ready to use. Now, head over to http://git.local:3000/projects/new to create a project. Add a repository in the next step, call it "mainline".

Now, get back into your shell, create a mumbo-jumbo git repo:

mkdir -p ~/projects/mumbo-jumbo
cd ~/projects/mumbo-jumbo
touch .gitignore
git init
git add .
git commit -m "Initial commit"
git remote add origin git@git.local:/mumbo-jumbo/mainline.git
git push origin master

If this works, you're done!

Setup Ultrasphinx indexing cronjob

You might want to run the Ultrasphinx indexing cronjob. Type in crontab -e and put this line in there:

* */1 * * * cd /var/www/git.myserver.com/gitorious && rake ultrasphinx:index RAILS_ENV=production

Setup logrotate

Create /etc/logrotate.d/gitorious:

cd /var/www/git.myserver.com/gitorious
sudo cp doc/templates/ubuntu/gitorious-logrotate /etc/logrotate.d/gitorious
sudo chmod +x /etc/logrotate.d/gitorious

The logrotate script template assumes that Gitorious lives in /var/www/gitorious. Update to match your path. Following this guide, that'd look like this:

/var/www/git.myserver.com/gitorious/log/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /etc/init.d/git-daemon restart > /dev/null 2>/dev/null || true
        /etc/init.d/git-ultrasphinx restart > /dev/null 2>/dev/null || true
        /bin/touch /var/www/git.myserver.com/gitorious/tmp/restart.txt > /dev/null 2>/dev/null || true
endscript
}

Wrapping up

Now you can set up passenger - don't worry, at this point deploying on Passenger is just like deploying any other Rails application. Add Capistrano to the mix if you want to keep working on your Gitorious installation locally - picking up new commits from the core team, adding your own tweaks and so on - and deploy updates every now and then. I have previously written a thorough guide on Capistrano and Passenger, but here are the highlights (for Passenger, this setup does not account for Capistrano).

Install Passenger

sudo gem install passenger
sudo passenger-install-apache2-module

The installer will instruct you to create /etc/apache2/mods-available/passenger.load and /etc/apache2/mods-available/passenger.conf.

Enable some Apache modules:

sudo a2enmod rewrite
sudo a2enmod deflate
sudo a2enmod passenger
sudo a2enmod expires

Create /var/www/git.myserver.com/conf/vhost.conf with:

<VirtualHost *>
    <Directory /var/www/git.myserver.com/gitorious/public>
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from All
    </Directory>

    DocumentRoot /var/www/git.myserver.com/gitorious/public
    ServerName git.myserver.com

    ErrorLog /var/www/git.myserver.com/log/error.log
    CustomLog /var/www/git.myserver.com/log/access.log combined

    # Gzip/Deflate
    # http://fluxura.com/2006/5/19/apache-for-static-and-mongrel-for-rails-with-mod_deflate-and-capistrano-support
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Far future expires date
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
        ExpiresActive On
        ExpiresDefault "access plus 1 year"
    </FilesMatch>

    # No Etags
    FileETag None

    RewriteEngine On

    # Check for maintenance file and redirect all requests
    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /system/maintenance.html [L]
</VirtualHost>

Symlink site

sudo ln -s /var/www/git.myserver.com/conf/vhost.conf \
    /etc/apache2/sites-available/git.myserver.com
sudo a2ensite git.myserver.com

Restart Apache

sudo /etc/init.d/apache2 restart

A word of warning: If you have SSL enabled on your Apache, Gitorious will want to use it, so if that's the case, set up a VirtualHost for port 443.

That's "all there is to it". If you had any trouble setting up Gitorious using this guide, please report back, I'd love to help and get this guide correct. As ar as I know, a .deb package is on it's way, which will make this whole process alot easier. In any case I'd still recommend you to go through this setup manually atleast once because it will make familiarize with the Gitorious architecture in a way a prepackaged install can never to.

I want to extend huge thanks to Johan for creating such an awesome project, and to Marius and all the other contributors for continuously improving it. Also, my deepest gratitude for all the help both Marius and Johan provided while I was compiling this guide.

Thanks alot to August for correcting a few minor mistakes while using this guide for Ubuntu JeOS 8.04.

Good luck, and do share your experiences in the comments!

I'm sorry to tell you that I am currently unable to handle the insane amounts of spam hitting this post, nor have I the time to fix a spam filter for eZ Publish right now, so I am closing down comments. Check out the official Gitorious mailing list/Google group if you need help.

By the way, follow me on Twitter here.

Published 23. September 2009 in ruby.

Possibly related