Installing Gitorious on Ubuntu 11.04

This guide is based on the Ubuntu Installation Guide from the Gitorious Wiki, but it is a little outdated, so here’s my updated version.

Sudo make sandwich

Pretty much all of the following commands need to be executed as the superuser, so first of all we make ourselves root (alternatively you could prepend sudo to every command, but that is rather tiresome. I do not recommend to always work as root though, because that way you will incur the wrath of the invisible pink unicorn):

$ sudo su
[sudo] password for :

# Install packages

When installing all these packages, you will be asked for a MySQL root password, which you should remember, because you will need it later on.

$ aptitude install \
    build-essential zlib1g-dev tcl-dev libexpat-dev libxslt1-dev \
    libcurl4-openssl-dev postfix apache2 mysql-server mysql-client \
    apg geoip-bin libgeoip1 libgeoip-dev sqlite3 libsqlite3-dev \
    imagemagick libpcre3 libpcre3-dev zlib1g zlib1g-dev libyaml-dev \
    libmysqlclient15-dev apache2-dev libonig-dev ruby-dev rubygems \
    libopenssl-ruby libdbd-mysql-ruby libmysql-ruby \
    libmagick++-dev zip unzip memcached git-core git-svn git-doc \
    git-cvs irb 
# Install Ruby Gems Apparently some of the gems required by Gitorious need at least RubyGems v1.4 to work, and Ubuntu 11.04 ships with v1.3.7, so you need to force-update RubyGems ("force" because usually you would update RubyGems through aptitude):
$ REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
Now we can install all the necessary gems:
$ gem install --no-ri --no-rdoc -v 0.8.7 rake && \
    gem install --no-ri --no-rdoc -v 1.1.0 daemons && \
    gem install -b --no-ri --no-rdoc \
        rmagick stompserver passenger bundler
**You may ask yourself why there are significantly less Gems here compared to the old guide. This is because bunder installs all those Gems automagically from the data in the `Gemfile.lock`** # Installing the Sphinx Search Server
$ wget && \
    tar -xzf sphinx-0.9.9.tar.gz && \
    cd sphinx-0.9.9 && \
    ./configure --prefix=/usr && \
    make all install
# Getting Gitorious
$ git clone git:// /var/www/gitorious && \
    cd /var/www/gitorious && \
    git submodule init && \
    git submodule update
Easy as pie. Now we just need to put the Gitorious binary on our path:
$ ln -s /var/www/gitorious/script/gitorious /usr/bin
# Configuring services Gitorious needs a bunch of background services, so we need to copy the supplied startup scripts:
$ cd /var/www/gitorious/doc/templates/ubuntu/ && \
    cp git-daemon git-poller git-ultrasphinx stomp /etc/init.d/ && \
    cd /etc/init.d/ && \
    chmod 755 git-daemon git-poller git-ultrasphinx stomp
and enable them:
$ update-rc.d git-daemon defaults && \
    update-rc.d git-poller defaults && \
    update-rc.d git-ultrasphinx defaults && \
    update-rc.d stomp defaults
We need to create an additional symlink, because all the startup scripts have `RUBY_HOME` set to `/opt/ruby-enterprise` (alternatively we could just patch the files, but this way it is easier and you can update the scripts if needed):
$ ln -s /usr/ /opt/ruby-enterprise
# Configuring Apache ## Passenger First of all, we need to compile the Apache2 passenger module:
$ $(gem contents passenger | grep passenger-install-apache2-module)
The passenger configuration script will tell you exactly what you'll need to add to your apache configuration. The part you need to copy **looks like this** (don't use the snippet below, but use the one given to you by the passenger install script):
Please edit your Apache configuration file, and add these lines:

	LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/ext/apache2/
	PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.9
	PassengerRuby /usr/bin/ruby1.8

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
These three lines need to be inserted into
## Enabling necessary modules
$ a2enmod passenger && \
    a2enmod rewrite && \
    a2enmod ssl
## Creating the Apache2 sites * Create /etc/apache2/sites-available/gitorious (see files below) * Create /etc/apache2/sites-available/gitorious-ssl (see files below) Now we need to disable the default site, and enable our freshly created Gitorious sites:
$ a2dissite default && \
    a2dissite default-ssl && \
    a2ensite gitorious && \
    a2ensite gitorious-ssl
# Creating a MySQL user for gitorious
$ mysql -u root -p
Enter password: (your mysql root password you selected while installing the packages)

# Configuring Gitorious

First of all, we need to make sure we have all gems in the correct version for Gitorious, so we run the following:

$ cd /var/www/gitorious/ && \
	bundle install && \
	bundle pack
Now we can create the user under which Gitorious will run and serve the Git repositories:
$ adduser --system --home /var/www/gitorious/ --no-create-home --group --shell /bin/bash git && \
    chown -R git:git /var/www/gitorious
Then we need to create some stuff that Gitorious needs to run:
$ su - git && \
    mkdir .ssh && \
    touch .ssh/authorized_keys && \
    chmod 700 .ssh && \
    chmod 600 .ssh/authorized_keys && \
    mkdir tmp/pids && \
    mkdir repositories && \
    mkdir tarballs
## Creating the Gitorious configuration Lets copy the sample configuration files to the correct path:
$ cp config/database.sample.yml config/database.yml && \
    cp config/gitorious.sample.yml config/gitorious.yml && \
    cp config/broker.yml.example config/broker.yml
Now edit the `config/database.yml` and make sure you set the correct username and password in the `production` section. After that, we need to set a couple of things in `config/gitorious.yml`: * Make sure you are configuring the right section (not `test:`, but `production:`) * **repository_base_path** should be `/var/www/gitorious/repositories` * **cookie_secret** needs to be set to a random value >= 30 characters * **gitorious_client_port** should be 80 * **gitorious_host** needs to be the exact hostname that clients will use (cookies get messed up otherwise) * **archive_cache_dir** should be `/var/www/gitorious/tarballs` * **archive_work_dir** should be something like `/tmp/tarballs-work` * **hide_http_clone_urls** should be true (they require extra unknown setup to work) * **is_gitorious_dot_org** should be false # Creating the Gitorious database Because of an [incompatibility of RubyGems with Rails < 2.3.11]( you need to add the following line at the top of `config/boot.rb`:
require 'thread'
Now we let `rake` do all the work for us:
$ export RAILS_ENV=production && \
    bundle exec rake db:create && \
    bundle exec rake db:migrate && \
    bundle exec rake ultrasphinx:bootstrap
# Create the Sphinx Cronjob
$ crontab -e * * * * * cd /var/www/gitorious && /usr/bin/bundle exec rake ultrasphinx:index RAILS_ENV=production
# Create an admin user
env RAILS_ENV=production ruby1.8 script/create_admin
# Reboot You're finally done. Reboot your Ubuntu machine, and your Gitorious installation should be up and running. If you find an error, feel free to leave a comment and I will fix it as soon as possible :) # Files ## gitorious
<VirtualHost *:80>
    DocumentRoot /var/www/gitorious/public
## gitorious-ssl

        DocumentRoot /var/www/gitorious/public
        SSLEngine on
        SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
        BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0