Redmine: Difference between revisions

From Alpine Linux
m (add mysql to lbu)
No edit summary
Line 1: Line 1:
Install Lighttpd with FastCGI
NOTE: This is a complete rewrite of our Redmine install how-to. Previously, Ruby packages needed by Redmine needed to be installed manually with rubygems. Now we have Ruby packages needed for Remine in our repository. As of writing, ruby packages are maintained in testing repository.
{{:Setting Up Lighttpd With FastCGI}}


Install extra packages for redmine:
Some assumptions:
apk add fcgi mysql mysql-dev rubygems fcgi-dev sqlite-dev


Install the following rubygems (gem install <gemname> --version <version>).  Note: newer versions of the gems may work, but these have been confirmed working in Alpine 2.1.2:
* For this how-to we assume you are running an Hard-disk install of Alpine Linux. If you are running from RAM, please make sure you use LBU.
gem install -V --no-rdoc --no-ri actionmailer --version 2.3.3
* Alpine Linux uses Lighttpd as default web-server. Redmine will be running with FastCGI inside Lighttpd. If you like to install Redmine with any other web-server, you will need to install it manually. Which are currently: ruby-rails ruby-fcgi ruby-rmagick ruby-i18n ruby-openid rubygems
gem install -V --no-rdoc --no-ri activerecord --version 2.3.3
* We are using MySQL as database for our Redmine install. Redmine is also able to run with PostgreSQL or SQLite.
gem install -V --no-rdoc --no-ri activeresource --version 2.3.3
* MySQL is running on a remote location. Please follow other tutorials on how to setup MySQL(need link).
gem install -V --no-rdoc --no-ri edavis10-object_daddy --version 0.4.3
* Detailed information regarding Redmine installation can be found: http://www.redmine.org/projects/redmine/wiki/RedmineInstall
gem install -V --no-rdoc --no-ri fcgi --version 0.8.8
gem install -V --no-rdoc --no-ri mocha --version 0.9.10
gem install -V --no-rdoc --no-ri mysql --version 2.8.1
gem install -V --no-rdoc --no-ri rails --version 2.3.3
  gem install -V --no-rdoc --no-ri shoulda --version 2.10.3
gem install -V --no-rdoc --no-ri sqlite3 --version 1.3.3


Configure MySql
Let's go on to the install part:


/usr/bin/mysql_install_db --user=mysql
Installing Redmine:
/etc/init.d/mysql start && rc-update add mysql default
/usr/bin/mysqladmin -u root password 'password'


Create the redmine database
apk install redmine


mysql -u root -p
On a Alpine base install this should probably pull in approximately 38 packages including (almost) all Ruby dependencies and Lighttpd. If you like to run a different webserver, you will need to skip redmine package and install all deps manually with apk.
For Redmine to communicate with MySQL server we will need to have the mysql ruby package. (if you want to run another db, just install the appropriate db package).


  create database redmine character set utf8;
  apk install ruby-mysql
grant all privileges on redmine.* to 'redmine'@'localhost' identified by 'Secur3P@ass';
flush privileges;
exit


Create redmine folder
Now before we continue we need to prepare our database. According Redmine website you need to do the following:


  mkdir -p /usr/share/webapps/redmine
  create database redmine character set utf8;
 
  create user 'redmine'@'localhost' identified by 'my_password';
Download, unpack and move Redmine
  grant all privileges on redmine.* to 'redmine'@'localhost';
 
  cd /tmp/
wget http://rubyforge.org/frs/download.php/73140/redmine-1.0.3.tar.gz
  tar zxvf redmine-1.0.3.tar.gz
mv redmine-1.0.3/* /usr/share/webapps/redmine/
 
Change permissions
 
chown -R lighttpd:lighttpd /usr/share/webapps/redmine
chmod 0666 /usr/share/webapps/log/production.log
mkdir /var/run/redmine
chown lighttpd:lighttpd /var/run/redmine
 
Edit the database config file and add the mysql password at every occurrence of "password:"
 
cp /usr/share/webapps/redmine/config/database.yml.example /usr/share/webapps/redmine/config/database.yml
nano /usr/share/webapps/redmine/config/database.yml


Some more steps
If you need mysql client, you can install it like this:


  cd /usr/share/webapps/redmine
  apk add mysql-client
mv public/dispatch.fcgi.example public/dispatch.fcgi


rake generate_session_store
You can of course also use a tool like phpmyadmin to create the database and setup the user.
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data


Note: keep default language of '''en'''
Redmine default config files are located inside /etc/redmine. For Redmine to find your database, please edit database.yml. We have removed all entries accept the default production one. For examples please check: /var/www/localhost/htdocs/redmine/config
If you need to edit additional configuration files, please move them to /etc/redmine and link them back to the original location. This way apk will use config protect and not overwrite your config files on update. Don't forget to edit the other files, like your SMTP configuration.


Start the Redmine testing webserver
First we need to generate a session store secret:


  ruby /usr/share/webapps/redmine/script/server webrick -e production
  cd /var/www/localhost/htdocs/redmine
/usr/lib/ruby/gems/1.8/bin/rake generate_session_store


Now you can browse to '''localhost:3000''' an log using '''admin''' user and '''admin''' password.
Now we populate the database:


Once Redmine is confirmed working, kill webrick.
cd /var/www/localhost/htdocs/redmine
RAILS_ENV=production /usr/lib/ruby/gems/1.8/bin/rake db:migrate


Set up lighttpd by editing lighttpd.conf.
Now our database is ready, we need to configure Lighttpd. We have included an example Redmine/Ligghtpd configuration based on FastCGI. You can find it in /etc/lighttpd.
: Uncomment the following line:
When you are finished setting up Ligghtpd configuation include it inside lighttpd.conf and we can start it.
    "mod_alias",
: Add the following content to the end of the file:
$HTTP["url"] =~ "^/redmine/" {
  alias.url = ("/redmine" => "/usr/share/webapps/redmine/public")
  server.document-root = "/usr/share/webapps/redmine/public/"
  server.error-handler-404 = "/redmine/dispatch.fcgi"
  index-file.names        = ("dispatch.fcgi")
  # Change *-procs to 2 if you need to use Upload Progress or other tasks that
  # *need* to execute a second request while the first is still pending.
  fastcgi.server          += (
        ".fcgi" => (
                "localhost" => (
                        "min-procs"      => 1,
                        "max-procs"      => 2,
                        "check-local"    => "disable",
                        "socket"          => "/var/run/redmine/fcgi.socket",
                        "bin-path"        => "/usr/bin/ruby /usr/share/webapps/redmine/public/dispatch.fcgi",
                        "bin-environment" => (
                                "RAILS_ENV"              => "production"
                        )
                )
        )
  )
}


Configure a relative URL by editing /usr/share/webapps/redmine/config/environment.rb: Add the line shown below, within the code block "Rails::Initializer.run do |config|"
/etc/init.d/lighttpd start
config.action_controller.relative_url_root = '/redmine'


Restart lighttpd
If your server does not run, you can find information in /var/log/lighttpd. If that does not provide a clue you can also run Lighttpd in foreground. It should display some more debug information.
/etc/init.d/lighttpd restart


Note: To enable email to ticket creation from unknown users/email addresses (after allowing anonymous issue creation within Redmine UI) for the 'myproject' project in Redmine:
/etc/init.d/lighttpd stop
lighttpd -f /etc/lighttpd/lighttpd.conf -D


  #!/usr/bin/perl
  # Author: Jeff Bilyk
  # March 2, 2011
  #Script to take email from stdin, then:
  # - Check redmine database to see if the user exists
  #  - If user doesn't exist, create the user
  # - Pass the email on the redmine utility:
  #  - echo "email contents" | rake redmine:email:read RAILS_ENV="production" project=myproject
 
  use strict;
  use DBI;
  # global variables
  my $DbName = 'redmine';
  my $DbUser = 'redmine';
  my $DbPassword = 'Secur3P@ass';
  my @fields;
  my @address;
  my $existinguser;
 
  # Get email from stdin
  my @email = <STDIN>;
 
  # Parse field for "for"
  foreach (@email)
  {
  if ($_ =~ /From/)
  {
  @fields = (split /</,$_);
  @address = (split />/,$fields[1]);
  }
  }
 
  my $dbh = DBI->connect('dbi:mysql:' . $DbName, $DbUser, $DbPassword, { PrintError => 0 }) or die "SQL Connect Error:" . DBI->errstr;
 
  # Find out if there're any existing users with the specified email address
  my $sqlStatement = "SELECT * from users where mail = '$address[0]';";
 
  my $sqlCommand = $dbh->prepare($sqlStatement);
 
  $sqlCommand->execute or die "SQL Error: " . DBI->errstr;
 
  my @sqlRecordset;
  $existinguser = 'maybe';
 
  @sqlRecordset = $sqlCommand->fetchrow_array;
 
  if ($sqlRecordset[0] == '') {
  printf "@sqlRecordset \n";
  $existinguser = 'no';
  }
  else {
  $existinguser = 'yes';
  }
 
  # If there isn't a user already, then create one
  if ($existinguser == 'no')
  {
  my @name = (split /@/,$address[0]);
  printf "Current variables: $name[0]  $address[0]  \n";
  $sqlStatement = "INSERT INTO users (login, firstname, lastname, mail, mail_notification, admin, status, language, type) values (\"$name[0]\", \"$name[0]\", \" \", \"$address[0]\", 0, 0, 1, \"en\", \"User\");";
  $sqlCommand = $dbh->prepare($sqlStatement);
  $sqlCommand->execute or die "SQL Error: " .DBI->errstr;
  printf "User created";
  }
 
  my $timeinsec = `date +%s`;
  open (MYFILE, ">>/var/tmp/$timeinsec");
  print MYFILE "@email";
  close (MYFILE);
 
  system("sed -i 's/^  //' /var/tmp/$timeinsec");
  system("sed -i 's/^ //' /var/tmp/$timeinsec");
 
  `cd /usr/share/webapps/redmine && rake redmine:email:read RAILS_ENV="production" project=myproject < /var/tmp/$timeinsec`;
  exit 0


Configure LBU
This document is a Work In Progress.
lbu inc /usr/lib/ruby
lbu inc /usr/share/webapps
lbu inc /var/lib/mysql

Revision as of 08:54, 15 June 2011

NOTE: This is a complete rewrite of our Redmine install how-to. Previously, Ruby packages needed by Redmine needed to be installed manually with rubygems. Now we have Ruby packages needed for Remine in our repository. As of writing, ruby packages are maintained in testing repository.

Some assumptions:

  • For this how-to we assume you are running an Hard-disk install of Alpine Linux. If you are running from RAM, please make sure you use LBU.
  • Alpine Linux uses Lighttpd as default web-server. Redmine will be running with FastCGI inside Lighttpd. If you like to install Redmine with any other web-server, you will need to install it manually. Which are currently: ruby-rails ruby-fcgi ruby-rmagick ruby-i18n ruby-openid rubygems
  • We are using MySQL as database for our Redmine install. Redmine is also able to run with PostgreSQL or SQLite.
  • MySQL is running on a remote location. Please follow other tutorials on how to setup MySQL. (need link).
  • Detailed information regarding Redmine installation can be found: http://www.redmine.org/projects/redmine/wiki/RedmineInstall

Let's go on to the install part:

Installing Redmine:

apk install redmine

On a Alpine base install this should probably pull in approximately 38 packages including (almost) all Ruby dependencies and Lighttpd. If you like to run a different webserver, you will need to skip redmine package and install all deps manually with apk. For Redmine to communicate with MySQL server we will need to have the mysql ruby package. (if you want to run another db, just install the appropriate db package).

apk install ruby-mysql

Now before we continue we need to prepare our database. According Redmine website you need to do the following:

create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'my_password';
grant all privileges on redmine.* to 'redmine'@'localhost';

If you need mysql client, you can install it like this:

apk add mysql-client

You can of course also use a tool like phpmyadmin to create the database and setup the user.

Redmine default config files are located inside /etc/redmine. For Redmine to find your database, please edit database.yml. We have removed all entries accept the default production one. For examples please check: /var/www/localhost/htdocs/redmine/config If you need to edit additional configuration files, please move them to /etc/redmine and link them back to the original location. This way apk will use config protect and not overwrite your config files on update. Don't forget to edit the other files, like your SMTP configuration.

First we need to generate a session store secret:

cd /var/www/localhost/htdocs/redmine
/usr/lib/ruby/gems/1.8/bin/rake generate_session_store

Now we populate the database:

cd /var/www/localhost/htdocs/redmine
RAILS_ENV=production /usr/lib/ruby/gems/1.8/bin/rake db:migrate

Now our database is ready, we need to configure Lighttpd. We have included an example Redmine/Ligghtpd configuration based on FastCGI. You can find it in /etc/lighttpd. When you are finished setting up Ligghtpd configuation include it inside lighttpd.conf and we can start it.

/etc/init.d/lighttpd start

If your server does not run, you can find information in /var/log/lighttpd. If that does not provide a clue you can also run Lighttpd in foreground. It should display some more debug information.

/etc/init.d/lighttpd stop
lighttpd -f /etc/lighttpd/lighttpd.conf -D


This document is a Work In Progress.