Project

General

Profile

Actions

HowTo Install Redmine 12x with Mercurial and Subversion on Ubuntu Server 1004 » History » Revision 24

« Previous | Revision 24/56 (diff) | Next »
Dimitry Profus, 2011-09-20 02:16


HowTo Install Redmine 1.2.x with Mercurial and Subversion on Ubuntu Server 10.04

Redmine Installation

  1. Install the LAMP stack
    $ sudo tasksel install lamp-server
    
  2. Install the required packages
    $ sudo apt-get install build-essential subversion llibmysqlclient15-dev libdigest-sha1-perl libgemplugin-ruby libgemplugin-ruby1.8 libruby-extras libruby1.8-extras rails rake ruby rubygems rubygems1.8 ruby1.8-dev libopenssl-ruby1.8 
    
  3. Install the required Ruby gems
    $ sudo gem install rails -v=2.3.11 --no-ri --no-rdoc
    $ sudo gem install rake -v=0.8.7 --no-ri --no-rdoc
    $ sudo gem uninstall rake -v=0.9.2 
    $ sudo gem install i18n -v=0.4.2 --no-ri --no-rdoc
    $ sudo gem install mysql --no-ri --no-rdoc
    
  4. Download Redmine into /user/share/redmine directory
    $ sudo svn co http://redmine.rubyforge.org/svn/branches/1.2-stable /usr/share/redmine
    
  5. Create an empty MySQL database and accompanying user named redmine for example.
    $ mysql -u root -p
    (enter the mysql root user password)
    > create database redmine character set utf8;
    > create user 'redmine'@'localhost' identified by '[password]';
    > grant all privileges on redmine.* to 'redmine'@'localhost' identified by '[password]';
    > exit
    
  6. Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment.
    $ sudo cp /usr/share/redmine/config/database.yml.example /usr/share/redmine/config/database.yml
    
    $ sudo nano /usr/share/redmine/config/database.yml
    
    Modify to the following and save (ctrl+x)
    
    production:
      adapter: mysql
      socket: /var/run/mysqld/mysqld.sock
      database: redmine
      host: localhost
      username: redmine
      password: [password]
      encoding: utf8
    
  7. Generate a session store secret.
    $ cd /usr/share/redmine
    
    $ sudo rake generate_session_store
    
  8. Create the database structure, by running the following command under the application root directory:
    $ cd /usr/share/redmine
    
    $ sudo rake db:migrate RAILS_ENV="production" 
    
  9. Insert default configuration data in database, by running the following command:
    $ sudo RAILS_ENV=production rake redmine:load_default_data
    
  10. Setting up permissions
    $ cd /usr/share/redmine
    $ sudo chown -R www-data:www-data files log tmp public/plugin_assets
    $ sudo chmod -R 755 files log tmp public/plugin_assets
    
  11. Test using the webrick web server
    $ cd /usr/share/redmine
    
    $ ruby script/server webrick -e production
    
    Point your web browser at http://[my server ip]:3000
    
    You should now see the application welcome page.
    

Apache Integration

  1. Install the required packages
    $ sudo apt-get install libapache2-mod-passenger
    
  2. Add a symbolic link to the public redmine web directory
    $ sudo ln -s /usr/share/redmine/public /var/www/redmine
    
  3. Configure Passanger to run as www-data
    $ sudo nano /etc/apache2/mods-available/passenger.conf
    
    Add the follow line and save (ctrl+x)
    
    PassengerDefaultUser www-data
    
  4. Create a new Apache site file
     
    $ sudo nano /etc/apache2/sites-available/redmine 
    

    Add the following lines and save (ctrl+x)
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www
            ServerName myservername
    
            RewriteEngine on
            RewriteRule   ^/$  /redmine  [R]
    
            <Directory /var/www/redmine>
                    RailsBaseURI /redmine
                    PassengerResolveSymlinksInDocumentRoot on
            </Directory>
    
            ErrorLog /var/log/apache2/error.log
    
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
            LogLevel warn
    
            CustomLog /var/log/apache2/access.log combined
    </VirtualHost>
    

    For SSL add the following text instead
    <VirtualHost *:443>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www
            ServerName myservername
    
            SSLEngine On
            SSLCertificateFile /etc/apache2/ssl/redmine.pem
    
            RewriteEngine on
            RewriteRule   ^/$  /redmine  [R]
    
            <Directory /var/www/redmine>
                    RailsBaseURI /redmine
                    PassengerResolveSymlinksInDocumentRoot on
            </Directory>
    
            ErrorLog /var/log/apache2/error.log
    
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
            LogLevel warn
    
            CustomLog /var/log/apache2/access.log combined
    </VirtualHost>
    
  5. Enable the Redmine website
    $ sudo a2dissite default
    $ sudo a2ensite redmine
    
  6. Enable the Passenger and Rewite modules and restart Apache
    $ sudo a2enmod passenger
    $ sudo a2enmod rewrite
    $ sudo /etc/init.d/apache2 restart
    
  7. Test the setup
    Open up your favorite web browser and goto
    
    http://[my site or ip]/redmine
    

Mercurial Integration

  1. Install the latest Mercurial release
    $ sudo apt-get install python-software-properties
    $ sudo add-apt-repository ppa:mercurial-ppa/releases
    $ sudo apt-get update
    $ sudo apt-get install mercurial libapache-dbi-perl libapache2-mod-perl2
    
  2. Create the hg web directory
    $ sudo mkdir -p /var/hg/repos
    
  3. Create the web cgi script file
    $ sudo nano /var/hg/hgwebdir.cgi
    
    Add the following and save
    
    #!/usr/bin/env python
    #
    from mercurial import demandimport; demandimport.enable()
    from mercurial.hgweb.hgwebdir_mod import hgwebdir
    import mercurial.hgweb.wsgicgi as wsgicgi
    application = hgwebdir('hgweb.config')
    wsgicgi.launch(application)
    
  4. Create the cgi web config file
    $ sudo nano /var/hg/hgweb.config
    
    Add the following and save
    
    [paths]
    /=/var/hg/repos/**
    
    [web]
    allow_push = *
    push_ssl = false
    allowbz2 = yes
    allowgz = yes
    allowzip = yes
    
  5. Setup permissions
    $ sudo chown -R www-data:www-data /var/hg
    $ sudo chmod gu+x /var/hg/hgwebdir.cgi
    
  6. Create a Apache config file
    $ sudo nano /etc/apache2/conf.d/hg.config
    
    Add the following and save
    
    PerlLoadModule Apache::Redmine
    ScriptAlias /hg  "/var/hg/hgwebdir.cgi" 
    <Location /hg  >
        AuthType Basic
        AuthName "Redmine Mercurial Repository" 
        Require valid-user
    
        #Redmine auth
        PerlAccessHandler Apache::Authn::Redmine::access_handler
        PerlAuthenHandler Apache::Authn::Redmine::authen_handler
        RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
        RedmineDbUser "redmine" 
        RedmineDbPass "password" 
    </Location>
    
  7. Add a symbolic link to Redmine.pm
    $ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
    $ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
    
  8. Enable the required Apache modules and restart Apache
    $ sudo /etc/init.d/apache2 restart
    
  9. Create a new test repository and project in Redmine
    $ sudo hg init /var/hg/repos/test
    $ sudo chown -R www-data:www-data /var/hg/repos/test
    
    Create a new project with and identifier 'test'
    
    In the project Settings > Repository set
    SCM: Mercurial
    Path to repository: /var/hg/repos/test
    Press the 'Create' button
    
    Goto to the Repository tab of the test project
    
  10. View the test repository in the web browser
    > http://[my site name]/hg/test
    

Subversion Integration

  1. Install the latest Mercurial release
    $ sudo apt-get install subversion libapache2-svn libapache-dbi-perl libapache2-mod-perl2
    
  2. Create the svn repository directory
    $ sudo mkdir /var/svn
    
  3. Setup permissions
    $ sudo chown -R www-data:www-data /var/svn
    
  4. Add a symbolic link to Redmine.pm
    $ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
    $ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
    
  5. Create a Apache config file
    $ sudo nano /etc/apache2/conf.d/svn.config
    

    Add the following and save
    PerlLoadModule Apache::Redmine
    <Location /svn>
        DAV svn
        SVNParentPath "/var/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 Subversion Repository" 
    
        #read-only access    
        <Limit GET PROPFIND OPTIONS REPORT>
            Require valid-user
            Allow from [my server ip]
            # Allow from another-ip
             Satisfy any
        </Limit>
            # write access
            <LimitExcept GET PROPFIND OPTIONS REPORT>
            Require valid-user
        </LimitExcept>
    
        ## for mysql
        RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
        RedmineDbUser "redmine" 
        RedmineDbPass "password" 
    </Location>
    
  6. Enable the required Apache modules and restart Apache
    $ sudo a2enmod dav_svn
    $ sudo /etc/init.d/apache2 restart
    
  7. Create a new test repository
    $ sudo svnadmin create /var/svn/test
    $ sudo chown -R www-data:www-data /var/svn/test
    

Automate Repository Creation

  1. Enable WS for repository management and generate and API key
    * From the Redmine Administration menu select Settings
    * Click on the Repositories tab
    * Enable the 'Enable WS for repository management' checkbox
    * Click the 'Generate a key' link 
    * Press the 'Save' button
    
  2. Modify reposman.rb
    $ sudo nano /usr/share/extra/svn/reposman.rb
    
    Add the following to module SCM and save  
    
      module Mercurial
        def self.create(path)
          Dir.mkdir path
          Dir.chdir(path) do
            system_or_raise "hg init" 
          end
        end
      end
    
  3. Schedule the reposman.rb script to run every minute
    $ sudo nano /etc/cron.d/redmine
    

    Add one of the following lines (not both) and save.
    (Note: you will need to replace [my API key] with the API key you generated in step 1)
    .
    To create subversion repositories add:
    * * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Subversion --svn-dir /var/hg/repos --owner www-data --url file:///var/svn --key=[my API key] >> /var/log/reposman.log
    

    OR to create Mecurial repositories add:
    * * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Mercurial --svn-dir /var/hg/repos --owner www-data --url /var/hg/repos --key=[my API key] >> /var/log/reposman.log
    

Automatic refresh of repositories in Redmine

  1. Schedule the fetch_changesets script to run every 15 minutes
    $ sudo nano /var/cron.d/redmine
    
    Add the following line and save
    
    */15 * * * * root ruby /usr/share/redmine/script/runner "Repository.fetch_changesets" -e production > /dev/null 2>&1
    
  2. Setup a changegroup script on the Mercurial server to run fetch_changesets after each push to a Mercurial repository
    $ sudo nano /var/hg/changegroup-hook
    

    Add the following text and save
    (Note: you will need to replace [your API key] the API key you generated in Redmine
    #!/bin/sh
    curl "http://localhost/redmine/sys/fetch_changesets?key=[your API key]"  > /dev/null 2>&1
    

    Setup permissions
    $ sudo chown www-data:www-data /var/hg/changegroup-hook
    $ sudo chmod ug+x /var/hg/changegroup-hook
    

    Modify the hgweb.config file
    $ sudo nano /var/hg/hgweb.config
    

    Add the following section and save
    [hooks]
    changegroup = /var/hg/changegroup-hook
    

Email Integration

  1. Install and configure Sendmail
    $ sudo apt-get install sendmail
    $ sudo sendmailconfig
    
    (Answer Yes to all questions which you will be asked)
    
  2. Update the Redmine configuration file
    $ sudo nano /usr/share/redmine/config/configuration.yml
    
    Add the following text and save
    
     production:
       email_delivery:
         delivery_method: :sendmail
    

Backup to Amazon S3 cloud storage

  1. Create an account at http://aws.amazon.com/
  2. Create a S3 bucket using the aws management console https://console.aws.amazon.com/ec2/home
  3. View your Access Keys at https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
  4. Build and install fuse to 2.8.4
    $ sudo wget https://launchpad.net/ubuntu/+archive/primary/+files/fuse_2.8.4.orig.tar.gz
    $ cd fuse-2.8.4/
    $ tar xzf fuse_2.8.4.orig.tar.gz 
    $ sudo ./configure 
    $ sudo make
    $ sudo make install
    
  5. Build and install s3fs 1.61
    $ sudo apt-get install libxml2-dev
    $ wget http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz
    $ tar xzf s3fs-1.61.tar.gz 
    $ cd s3fs-1.61/
    $ sudo ./configure 
    $ sudo make
    $ sudo make install
    
  6. Setup s3fs password file
    $ sudo nano /etc/passwd-s3fs
    

    Added your 'Access Key ID' and 'Secret Access Key' separated by a colon
    [accessKeyId]:[secretAccessKey]
    

    Setup permissions
    sudo chmod 650 /etc/passwd-s3fs
    
  7. Create mounting point
    $ sudo mkdir /mnt/s3
    

    #Mount your S3 bucket
    $ sudo s3fs [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
    
  8. Test it worked
    $ echo hello > welcome.txt
    $ ls /mnt/s3
    
  9. Create upstart job to mount the s3 file system start up
    $ sudo nano /etc/init/s3.conf
    

    Add the following text and save.
    description "Mount Amazon S3 file system and on system start" 
    
    start on (local-filesystems and net-device-up IFACE!=lo)
    stop on runlevel [016]
    
    respawn
    
    exec s3fs -f [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
    
  10. Create the backup script file
    $ sudo nano /usr/local/bin/backup-redmine
    
    Add the following text and save.
    
    #!/bin/bash
    ####################################
    #
    # Backup Redmine to S3 mount script with
    # grandfather-father-son rotation.
    #
    ####################################
    
    # Dump the redmine database
    mkdir /var/redmine-database-backup 2> /dev/null
    mysqldump --user=redmine --password=[your-db-password] --single-transaction redmine > /var/redmine-database-backup/redmine-db-dump.sql
    
    # What to backup. 
    backup_files="/var/redmine-database-backup /usr/share/redmine/files /var/hg /etc/apache2/conf.d /etc/apache2/sites-available" 
    
    # Where to backup to.
    dest="/mnt/s3" 
    
    # Setup variables for the archive filename.
    day=$(date +%A)
    hostname=$(hostname -s)
    
    # Find which week of the month 1-4 it is.
    day_num=$(date +%d)
    if (( $day_num <= 7 )); then
            week_file="$hostname-week1.tgz" 
    elif (( $day_num > 7 && $day_num <= 14 )); then
            week_file="$hostname-week2.tgz" 
    elif (( $day_num > 14 && $day_num <= 21 )); then
            week_file="$hostname-week3.tgz" 
    elif (( $day_num > 21 && $day_num < 32 )); then
            week_file="$hostname-week4.tgz" 
    fi
    
    # Find if the Month is odd or even.
    month_num=$(date +%m)
    month=$(expr $month_num % 2)
    if [ $month -eq 0 ]; then
            month_file="$hostname-month2.tgz" 
    else
            month_file="$hostname-month1.tgz" 
    fi
    
    # Create archive filename.
    if [ $day_num == 1 ]; then
            archive_file=$month_file
    elif [ $day != "Saturday" ]; then
            archive_file="$hostname-$day.tgz" 
    else 
            archive_file=$week_file
    fi
    
    # Print start status message.
    echo "Backing up $backup_files to $dest/$archive_file" 
    date
    echo
    
    # Backup the files using tar.
    tar czfP $dest/$archive_file $backup_files
    
    # Print end status message.
    echo
    echo "Backup finished" 
    date
    
    # Long listing of files in $dest to check file sizes.
    ls -lh $dest/
    
  11. Setup permissions
    sudo chmod ug+x /usr/local/bin/backup-redmine
    
  12. Schedule the backup to run once a day at 12am
    $ sudo nano /etc/cron.d/redmine
    
    Add the following line and save
    
    0 0 * * * root /usr/local/bin/backup-redmine
    
  13. Test the script
    $ sudo backup-redmine
    

Updated by Dimitry Profus about 13 years ago · 24 revisions