• Tutorial: Redmine with SVN, Git and Gitosis on Ubuntu 8.04

    by  • October 30, 2010 • Linux, Server, Tutorials • 24 Comments

    This is a tutorial for installing redmine on Ubuntu 8.04 with SVN and Git integration (managed by Gitosis and a redmine gitosis plugin).

    UPDATE #1 – 2011-04-23: New Tutorial for Redmine with Git and Gitosis on Ubuntu 11.04:http://www.x2on.de/2011/04/23/tutorial-redmine-with-git-and-gitosis-on-ubuntu-11-04/

    1. Install redmine

    Get recent trunk version from github (currently 1.02)

    apt-get install git-core
    mkdir /var/www
    cd /var/www
    git clone git://github.com/edavis10/redmine.git

    Install packages

    apt-get install ruby ruby1.8-dev libgemplugin-ruby libgemplugin-ruby1.8  mysql-server apache2-mpm-prefork wget libruby-extras libruby1.8-extras rails subversion rake apache2-prefork-dev libapache-dbi-perl libapache2-mod-perl2 libdigest-sha1-perl libapache2-svn libmysqlclient15-dev build-essential libcurl4-openssl-dev cron

    Create database

    mysql -u root -p
    CREATE DATABASE redmine CHARACTER SET utf8;
    CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'my_password';
    GRANT ALL privileges ON redmine.* TO 'redmine'@'localhost';

    Configure Database Settings

    cp redmine/config/database.yml.example redmine/config/database.yml
    nano redmine/config/database.yml
    production:
      adapter: mysql
      database: redmine
      host: localhost
      username: redmine
      password: 47w8t2938qfge2
      encoding: utf8

    Install Rubygem (Ubuntu 8.04 has an older version)

    wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
    tar xvfz rubygems-1.3.7.tgz
    cd rubygems-1.3.7
    ruby setup.rb
    ln -s /usr/bin/gem1.8 /usr/bin/gem

    Install Rails + Rack

    gem install rails -v=2.3.5
    gem install rack -v=1.0.1
    gem install mysql

    Configure redmine

    cd /var/www/redmine
    chown -R www-data:www-data files log tmp public/plugin_assets
    chmod -R 755 files log tmp public/plugin_assets
    rake generate_session_store
    RAILS_ENV=production rake db:migrate
    RAILS_ENV=production rake redmine:load_default_data

    Test redmine

    ruby script/server webrick -e production

    Now you can check http://my_domain.com:3000 if everything works

    2. Apache Integration

    Install passenger (Modify version numbers if needed)

    gem install passenger
    echo "LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.0/ext/apache2/mod_passenger.so" > /etc/apache2/mods-available/passenger.load
    ln -s /etc/apache2/mods-available/passenger.load /etc/apache2/mods-enabled/passenger.load
    nano /etc/apache2/mods-available/passenger.conf
    PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.0
    PassengerRuby /usr/bin/ruby1.8

    Configure Apache

    nano /etc/apache2/sites-available/my_domain
        ServerName my_domain.com
     
        DocumentRoot /var/www/redmine/public
     
        ServerAdmin user@example.com
        LogLevel warn
        ErrorLog /var/log/apache2/redmine_error
        CustomLog /var/log/apache2/redmine_access combined
     
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    nano /etc/apache2/apache2.conf

    Add this at the end of the file:

    Include /etc/apache2/mods-available/passenger.conf

    Activate your site

    ln -s /etc/apache2/sites-available/my_domain /etc/apache2/sites-enabled/my_domain

    Remove default entry

    rm /etc/apache2/sites-enabled/000-default

    Restart Apache and it should work

    /etc/init.d/apache2 restart

    3. Subversion integration

    ln -s /var/www/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
    nano /etc/apache2/sites-available/svn
     # /svn location for users
     PerlLoadModule Apache::Redmine
     
       DAV svn
       SVNParentPath "/var/repos/svn"
       Order deny,allow
       Deny from all
       Satisfy any
     
       PerlAccessHandler Apache::Authn::Redmine::access_handler
       PerlAuthenHandler Apache::Authn::Redmine::authen_handler
       AuthType Basic
       AuthName "Redmine SVN Repository" 
     
       #read-only access
     
          Require valid-user
          Allow from my_domain.com
          Allow from localhost
           Satisfy any
     
       # write access
         Require valid-user
     
       ## Mysql-Settings
       RedmineDSN "DBI:mysql:database=redmine;host=localhost"
       RedmineDbUser "redmine"
       RedmineDbPass "my_password"
     
    #Security:
     
          Order deny,allow
          Allow from localhost
          Allow from my_domain.com
          Deny from all

     

    ln -s /etc/apache2/sites-available/svn /etc/apache2/sites-enabled/svn
    mkdir -p /var/repos/svn
    chown -R www-data:www-data /var/repos
    chmod 0750 /var/repos/svn

    Go to Administration – Settings – Repositories on your redmine site and enable “WS for repository management”. Then generate an API key.

    Test the automatic generation:

    ruby /var/www/redmine/extra/svn/reposman.rb --redmine my_domain.com --svn-dir /var/repos/svn --owner www-data --url http://my_domain.com/svn --verbose --key=my_api_key

    If everything works create an crontab for this:

    nano /etc/cron.d/redmine
    10 * * * * root ruby /var/www/redmine/extra/svn/reposman.rb --redmine my_domain.com --svn-dir /var/repos/svn --owner www-data --url http://my_domain.com/svn --verbose --key=my_api_key

    Now you are ready to use SVN with redmine

    4. Git integration

    Install needed packages:

    gem install inifile
    apt-get install libnet-ssh-ruby1.8 python-setuptools
    gem install lockfile
    easy_install pip
    pip install virtualenv

    Add an user for gitosis:

    adduser --system --shell /bin/bash --gecos 'Git Administrator' --group --disabled-password --home /opt/gitosis git

    Create an ssh-key (with empty passphrase):

    sudo -H -u git ssh-keygen -t dsa

    Create an Virtual Environment for python and install gitosis:

    sudo -u git virtualenv ~git/virtualenv
    sudo -u git ~git/virtualenv/bin/pip install git+git://eagain.net/gitosis.git
    echo "source $HOME/virtualenv/bin/activate" | sudo -u git tee -a ~git/.bashrc > /dev/null
    sudo -u git cat ~git/.ssh/id_dsa.pub | sudo -H -u git ~git/virtualenv/bin/gitosis-init

    Install redmine-gitosis plugin:

    cd /var/www/redmine/
    chown -R www-data:www-data /var/www/redmine
    script/plugin install git://github.com/rocket-rentals/redmine-gitosis.git

    Patch the plugin:

    nano /var/www/redmine/vendor/plugins/redmine-gitosis/lib/gitosis.rb
    require 'lockfile'
    require 'inifile'
    require 'net/ssh'
     
    module Gitosis
      # server config
      GITOSIS_URI = 'git@my_domain.com:gitosis-admin.git'
      GITOSIS_BASE_PATH = '/opt/gitosis/repositories/'
     
      # commands
      ENV['GIT_SSH'] = SSH_WITH_IDENTITY_FILE = File.join(RAILS_ROOT, 'vendor/plugins/redmine-gitosis/extra/ssh_with_identity_file.sh')

    Configure SSH:

    mkdir /var/www/.ssh
    chown -R www-data:www-data /var/www/.ssh
    sudo -u www-data ssh my_domain.com

    Migrate plugin:

    rake db:migrate_plugins RAILS_ENV=production

    Remove standard ssh-key and change it to the created one:

    rm /var/www/redmine/vendor/plugins/redmine-gitosis/extra/ssh/private_key
    cp ~git/.ssh/id_dsa /var/www/redmine/vendor/plugins/redmine-gitosis/extra/ssh/private_key
    chown -R www-data:www-data /var/www/redmine

    Test if the www-data user can read the key:

    sudo -u www-data cat /var/www/redmine/vendor/plugins/redmine-gitosis/extra/ssh/private_key

    Add the www-data user to the git group:

    usermod -a -G git www-data

    Have fun!

    Source:

    http://brantinteractive.com/2007/02/16/getting-the-mysql-gem-installed-on-ubuntu/
    http://www.redmine.org/wiki/1/RedmineInstall
    http://wiki.ousli.org/index.php/Redmine_in_Ubuntu_Jaunty_9.04
    http://www.redmine.org/wiki/1/HowTo_Install_Redmine_in_Ubuntu
    http://www.redmine.org/wiki/redmine/Repositories_access_control_with_apache_mod_dav_svn_and_mod_perl
    http://xdissent.com/2010/05/04/github-clone-with-redmine/
    http://wiki.ubuntuusers.de/virtualenv

    Sponsor

    24 Responses to Tutorial: Redmine with SVN, Git and Gitosis on Ubuntu 8.04

    1. David G.
      October 31, 2010 at 11:35

      Thanks for this great tutorial. I tried to integrate gitosis in redmine bevore…. With this tutorial here it works now!

    2. ivan
      November 1, 2010 at 12:47

      It does not work for -url file:///var/local/svn. There is a new string in reposman.log: this script requires activeresource and repository creation failed. Any suggestions what it means? Don’t pay attention to my English, I am from Russia.

    3. ivan
      November 2, 2010 at 05:34

      I need to make it works for -url file:///…. Did you try this possibility?

      • November 2, 2010 at 16:11

        No i didn’t try this. Perhaps you can find something in the redmine wiki for this…

    4. November 5, 2010 at 23:51

      I found I had to run

      passenger-install-apache2-module

      after the gem install passenger to get mod_passenger.so built

      But so far, a very useful tutorial — looking forward to getting svn and git set up.

    5. November 6, 2010 at 03:17

      I also needed

      easy_install virtualenv

      to get the git part working

      • November 6, 2010 at 10:20

        Thanks i forgot this line. But i used pip install virtualenv

    6. November 9, 2010 at 19:43

      I couldn’t get the SSH authentication to work. Ultimately determined that it was due to a security configuration in my sshd_conf file, the AllowUsers setting. You have to include the git user, or it will fail. You might want to add the following to your tutorial on the section where you set up SSH:

      Check the output of the following command:

      grep “AllowUsers” /etc/ssh/sshd_config

      If “AllowUsers” is present in the SSH daemon config, make sure you include the “git” user. (user names are separated by spaces)

    7. November 16, 2010 at 16:03

      Hi.
      I tried the tutorial on Ubuntu Server 10.10 and the step of automatic generation repository script (reposman.rb) didn’t work!!!
      When I run the script a message error appears: Unable to connect to http://192.168.0.1/sys/: Failed with 403 Forbidden
      I’ve seen the other tutorials in the end of article, but they didn’t help me….
      Someone had this problem? Can I help me?

    8. Shane Kerns
      November 16, 2010 at 19:23

      After the step for installing passenger there was no mod_passenger.so to be found anywhere. I am following this on Ubuntu 10.10.
      Any help would truly be appreciated.

    9. Shane Kerns
      November 16, 2010 at 19:47

      I posted something previously but I think it was lost somewhere. Anyway there doesn’t seem to be a mod_passenger.so after I followed the above mentioned and I get this error when I restart apache

      /etc/init.d/apache2 start
      * Starting web server apache2
      Syntax error on line 1 of /etc/apache2/mods-available/passenger.conf:
      Invalid command ‘PassengerRoot’, perhaps misspelled or defined by a module not included in the server configuration
      Action ‘start’ failed.
      The Apache error log may have more information.
      …fail!

      Any help would be appreciated

      • November 16, 2010 at 21:45

        You must have the module mod_passenger.so, to use PassengerRoot as command. Perhaps the path while building passenger is different in Ubuntu 10…

        • November 16, 2010 at 23:11

          In my case, after installed que passenger (gem install passenger), I have to compile the module. The script can be found in /var/lib/gems/1.8/bin/.
          Execute as root: ./passenger-install-apache2-module
          It’s a install assistent. It verify the dependecies before compile the module. It don’t download the dependencies.
          I hope to help you.

    10. muprhy
      November 19, 2010 at 11:19

      Hi, thanks for this walk through.
      I am running in problems hooking up svn in step 3 though. After running the reposman.rb script at the end of step 3, I get this error:

      Unable to connect to http://192.168.1.60/sys/: Failed with 403 Forbidden

      Even when I put an Allow from all objective in the configuration… So I think my config is messed up. On this site I can’t completely see all ‘s in the apache configs, so I guess somewhere in there I messed up :-(

      Maybe you can have a gist of the config’s availabe or so?

      Thanks!

      • November 19, 2010 at 14:39

        Please post your command for reposman.rb

        • November 25, 2010 at 11:59

          I have the same problem. Follow the command:
          ruby reposman.rb –redmine http://192.168.2.8 –svn-dir /var/svn –owner www-data -url http://192.168.2.8 –key bhEgNl9WriDxCVJcIGOM

          • November 25, 2010 at 16:31

            My command:
            ruby /var/www/redmine/extra/svn/reposman.rb –redmine my_domain.com –svn-dir /var/repos/svn –owner www-data –url http://my_domain.com/svn –verbose –key=my_api_key

            I think the problem is that you doesn’t use the /svn at -utl and you use http:// at -redmine

    11. Alex
      November 24, 2010 at 18:13

      confuse with the key verification. @_@

      [Thu Nov 25 00:52:28 2010] [notice] Apache/2.2.16 (Ubuntu) DAV/2 SVN/1.6.12 Phusion_Passenger/3.0.0 mod_perl/2.0.4 Perl/v5.10.1 configured — resuming normal operations
      /var/lib/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
      Could not create directory ‘/nonexistent/.ssh’.^M
      Host key verification failed.^M
      fatal: The remote end hung up unexpectedly

      • November 25, 2010 at 08:42

        Sounds like your apache user isn’t www-data… Then you must modifiy the following commands:
        mkdir /var/www/.ssh
        chown -R www-data:www-data /var/www/.ssh
        sudo -u www-data ssh my_domain.com

    12. Marisol Perry
      December 22, 2010 at 03:51

      I have the same problem. Follow the command: ruby reposman.rb –redmine http://192.168.2.8 –svn-dir /var/svn –owner www-data -url http://192.168.2.8 –key bhEgNl9WriDxCVJcIGOM

    13. April 23, 2011 at 09:13

      I made a new tutorial for install redmine with Git and Gitosis on Ubuntu 11.04: http://www.x2on.de/2011/04/23/tutorial-redmine-with-git-and-gitosis-on-ubuntu-11-04/

    14. stefan
      August 2, 2011 at 19:05

      My comments:
      Command:
      > CREATE USER ‘redmine’@'localhost’ IDENTIFIED BY ‘my_password’;
      failed, I had to enter:
      > CREATE USER ‘redmine’@’127.0.0.1′ IDENTIFIED BY ‘my_password’;

      Stefan

    15. stefan
      August 25, 2011 at 08:56

      Hello Felix!
      Please could you work on the HighLighting in the example of: /etc/apache2/sites-available/my_domain
      Important Parts of the code are not visable.
      Thank you! Stefan

    Leave a Reply

    Your email address will not be published. Required fields are marked *