Difference between revisions of "Redmine"

From Alpine Linux
Jump to: navigation, search
m (added example name to project)
(match config for rest of document)
Line 125: Line 125:
 
   use DBI;
 
   use DBI;
 
   # global variables
 
   # global variables
   my $DbName = 'redminetest';
+
   my $DbName = 'redmine';
   my $DbUser = 'redminetest';
+
   my $DbUser = 'redmine';
   my $DbPassword = 'ReDmInEtEsT';
+
   my $DbPassword = 'Secur3P@ass';
 
   my @fields;
 
   my @fields;
 
   my @address;
 
   my @address;

Revision as of 13:11, 22 March 2011

Note: We need to install using the edge repositories.

Change to the edge repository:

mv /etc/apk/repositories /etc/apk/repositories.old
echo -e "http://dl-3.alpinelinux.org/alpine/edge/main/" >> /etc/apk/repositories 

Update and upgrade

apk -U upgrade

Install services For installing the additional packages first activate community packages:

vi /etc/apk/repositories

Uncomment the following:

http://pkg.example.com/alpine/v3.11/community

Update the packagelist:

apk update

Install the additional packages:

apk add lighttpd php7-common php7-iconv php7-json php7-gd php7-curl php7-xml php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc php7-posix php7-mcrypt php7-gettext php7-ldap php7-ctype php7-dom

Configure Lighttpd

Edit lighttpd.conf

vi /etc/lighttpd/lighttpd.conf

Uncomment line:

include "mod_fastcgi.conf"


Edit mod_fastcgi.conf

vi /etc/lighttpd/mod_fastcgi.conf

Edit the section:

/usr/bin/php-cgi

To:

/usr/bin/php-cgi7

Start lighttpd service and add to needed runlevel

rc-service lighttpd start && rc-update add lighttpd default

Install extra packages:

apk add fcgi mysql mysql-dev rubygems

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:

actionmailer (2.3.3)
actionpack (2.3.3)
activerecord (2.3.3)
activeresource (2.3.3)
activesupport (2.3.3)
edavis10-object_daddy (0.4.3)
fcgi (0.8.8)
mocha (0.9.10)
mysql (2.8.1)
rack (1.0.1)
rails (2.3.3)
rake (0.8.7)
shoulda (2.10.3)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)

Configure MySql

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

Create the redmine database

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

Create redmine folder

mkdir -p /usr/share/webapps/redmine

Download, unpack and move Redmine

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

Edit the database config file and put the mysql 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

cd /usr/share/webapps/redmine
mv public/dispatch.fcgi.example public/dispatch.fcgi
rake generate_session_store
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data 

Note: keep default language of en

Start the Redmine testing webserver

ruby /usr/share/webapps/redmine/script/server webrick -e production

Now you can browse to localhost:3000 an log using admin user and admin password.

Once Redmine is confirmed working, kill webrick. Then setup lighttpd by editing lighttpd.conf:

$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"
                       )
               )
       )
 )
}

Restart lighttpd

/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:

 #!/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="test" 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="test" project=myproject < /var/tmp/$timeinsec`;
 exit 0