Installing Gitorious in Ubuntu 12.04 Server – How-To

Date January 9, 2013

I wanted to setup my own Git repository locally and with an accompanying front end GUI. Before Gitorious, I installed Git from scratch and also installed Gitolite. That will be another post later on.

Initially I followed the script from http://blog.kyodium.net/2011/09/install-gitorious-on-ubuntu-1104.html but its based on Ubuntu 11.04, there are some missing packages that was not part of the installation script so I had to run the script manually and jump from one tutorial to the other, but the main flow I used is from that script. This is the documentation of the installation process.

Note: I added the PPA to Git’s updated source so I would be using their latest release not Ubuntu’s Git package. ( Google around for Git’s PPA repository, its easy enough 😉 )

Also I was not logged into root ( which I prefer, so I had to do a lot of sudo-ing =S )

Execute these line-by-line… please don’y copy everything then go pressing enter.

Update your Ubuntu server to latest patches and install the packages bellow.

sudo aptitude install build-essential zlib1g-dev libcurl4-openssl-dev postfix apg geoip-bin libgeoip1 sqlite3 libsqlite3-dev libgeoip-dev libpcre3 libpcre3-dev zlib1g zlib1g-dev libyaml-dev libmysqlclient-dev libonig-dev zip unzip memcached git-core git-svn git-doc git-cvs libreadline-dev openjdk-6-jdk sqlite3 libsqlite3-dev libmagick++3 libmagick++-dev libapache2-mod-xsendfile libxslt1-dev libreadline5 libxslt-dev libxml2-dev imagemagick apache2-dev activemq

Update Ruby Gems

1
2
3
4
sudo REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
sudo gem install --no-ri --no-rdoc -v 0.8.7 rake 
sudo gem install --no-ri --no-rdoc -v 1.1.9 daemons
sudo gem install -b --no-ri --no-rdoc rmagick stompserver passenger bundler

Note: deamons was version 1.1.9 when I started the installation, you can check if they have newer releases and change the version number. Same goes with rake.

Install SphinxSearch

1
2
3
4
5
sudo wget http://sphinxsearch.com/files/sphinx-2.0.6.tar.gz
sudo tar -xzf sphinx-2.0.6.tar.gz
cd sphinx-2.0.6
sudo ./configure --prefix=/usr
sudo make all install

Note: Sphinx was version 2.0.6, check their website if there are updates.

Install Gitorious

1
2
3
4
5
6
sudo git clone git://gitorious.org/gitorious/mainline.git /var/www/gitorious
cd /var/www/gitorious
sudo git submodule init
sudo git submodule update
 
sudo ln -s /var/www/gitorious/script/gitorious /usr/bin

Configure Services

1
2
3
4
5
6
7
8
9
10
11
12
cd /var/www/gitorious/doc/templates/ubuntu
sudo cp git-daemon git-poller git-ultrasphinx stomp /etc/init.d/
 
cd /etc/init.d
sudo chmod 755 git-daemon git-poller git-ultrasphinx stomp
 
sudo update-rc.d git-daemon defaults
sudo update-rc.d git-poller defaults
sudo update-rc.d git-ultrasphinx defaults
sudo update-rc.d stomp defaults
 
sudo ln -s /usr/ /opt/ruby-enterprise

Configure Apache for Passenger

1
sudo $(gem contents passenger | grep passenger-install-apache2-module)

Note: Copy the 3 lines of codes displayed to be added to passenger.load file.

Open the file /etc/apache2/mods-available/passenger.load using for favorite text editor, I used vim.
Insert the code you copied before, the file should contain online these 3 lines, it should look something like this.

1
2
3
   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.18/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.18
   PassengerRuby /usr/bin/ruby1.8

Double check the gem version if it corresponds to the version installed in you server.

Enable Modules

1
2
3
sudo a2enmod passenger
sudo a2enmod rewrite
sudo a2enmod ssl

Create /etc/apache2/sites-available/gitorious
add the codes below…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<VirtualHost *:80>
   ServerName your.server.com
   DocumentRoot /var/www/gitorious/public
 
   ErrorLog /var/log/apache2/gitorious-error.log
   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn
 
   CustomLog /var/log/apache2/gitorious-access.log combined
 
   <IfModule mod_xsendfile.c>
     XSendFile on
     XSendFilePath /var/www/gitorious/tarballs
   </IfModule>
</VirtualHost>

Create /etc/apache2/sites-available/gitorious-ssl
Add the lines of code below…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        DocumentRoot /var/www/gitorious/public
        ErrorLog /var/log/apache2/gitorious-error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/gitorious-ssl_access.log combined
        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
        <IfModule mod_xsendfile.c>
            XSendFile on
            XSendFilePath /var/www/gitorious/tarballs
        </IfModule>
 
    </VirtualHost>
</IfModule>

Disable default site and enable Gitorious sites

1
2
3
4
sudo a2dissite default
sudo a2dissite default-ssl
sudo a2ensite gitorious
sudo a2ensite gitorious-ssl

Create MySQL database and gitorious user

1
2
3
4
5
6
$ mysql -u root -p
Enter password: <password here>
mysql> CREATE DATABASE IF NOT EXISTS gitorious_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
mysql> GRANT ALL PRIVILEGES ON gitorious_production.* TO 'gitorious'@'localhost' identified by 'YOUR_PASSWORD';
mysql> FLUSH PRIVILEGES;
mysql> exit

Configure Gitorious

1
2
3
cd /var/www/gitorious/
sudo bundle install
sudo bundle pack

Setup Git User

1
2
3
4
5
6
7
8
9
10
11
sudo adduser --system --home /var/www/gitorious/ --no-create-home --group --shell /bin/bash git
sudo chown -R git:git /var/www/gitorious
 
sudo su - git 
mkdir .ssh
touch .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
mkdir tmp/pids
mkdir repositories
mkdir tarballs

Setup Gitorious config files

1
2
3
4
sudo su - git
cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml
cp config/broker.yml.example config/broker.yml

Edit “/var/www/gitorious/config/database.yml” and comment everything except PRODUCTION
File should look similar to below.

1
2
3
4
5
6
7
8
...
production:
  adapter: mysql
  database: gitorious_production
  username: <gitorious username>
  password: <gitorious password>
  host: localhost
  encoding: utf8

Edit “/var/www/gitorious/config/gitorious.yml”
Set the following…

1
2
3
4
5
6
7
8
  repository_base_path: /var/www/gitorious/repositories
  gitorious_client_host: localhost
  gitorious_client_port: 80
  gitorious_host: <your hostname>
  archive_cache_dir: /var/www/gitorious/tarballs
  archive_work_dir: /tmp/tarballs-work
  hide_http_clone_urls: true
  is_gitorious_dot_org: false

Modify “/var/www/gitorious/config/environment.rb” by executing the code below.

1
2
3
4
sudo su - git
sed -i 's/^[ \t]*#[ \t]*no regular words .*/&\n  config.action_controller.session = { :key => \"_myapp_session\", :secret => \"<REPLACE_WITH_AT_LEAST_30_RANDOM_ALPHA_NUMERIC_CHARACTERS\" }/' $FILE
 
sed -i '/config.action_controller.session_store/ s/^\([ \t]*\)#/\1/' $FILE

Create Gitorious Database

1
2
3
4
5
6
7
8
9
10
11
su - git
mv config/boot.rb config/boot.bak
echo \"require 'thread'\" >> config/boot.rb
cat config/boot.bak >> config/boot.rb
 
cd /var/www/gitorious
export RAILS_ENV=production
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake thinking_sphinx:configure
bundle exec rake thinking_sphinx:index

Note: If “bundle exec rake db:create” produces an alert “<database_name> already exist“. You can disregard this since db:create only creates the database, and the tables will be created later in db:migrate.

Update crontab

1
2
3
sudo su - git
crontab -e
* * * * * cd /var/www/gitorious && /usr/bin/bundle exec /usr/bin/rake thinking_sphinx:index RAILS_ENV=production >/dev/null 2>&1

Note: If you want you can set it to every X min polling instead of every second. I set min to 5 min.

Configure ActiveMQ
Copy and Edit /etc/activemq/instances-available/gitorious/activemq.xml. Remove the predefined transportConnector and add a new one using the stomp protocol:
Thanks to http://edin.no-ip.com/blog/hswong3i/gitorious-ubuntu-12-04-mini-howto for this one.

1
2
3
4
5
6
7
8
sudo cp -rfp /etc/activemq/instances-available/main /etc/activemq/instances-available/gitorious
 
sudo sed -i 's/<transportConnector name=.*/<transportConnector name="stomp" uri="stomp:\/\/127.0.0.1:61613"\/>/g' /etc/activemq/instances-available/gitorious/activemq.xml
 
cd /etc/activemq/instances-enabled
sudo ln -s ../instances-available/gitorious .
 
/etc/init.d/activemq restart

Create Gitorious Admin User

1
2
su - git 
env RAILS_ENV=production ruby1.8 script/create_admin

DONE!
Restart your machine and login into your gitorious installation at
http://<ip_address_OR_host_name>

Sources:

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>