26 September 2010

RedMine (Synology)

RedMine is a great project/content management targeted at developers. I'm personnally using it as a complementary tool alongside Mercurial source code repository (cf previous posts):

And after a terrible fight, i managed to get Redmine running on my Synology through Apache.

First, Redmine is coded with Ruby, and that's partially a problem concerning the webserver to run this Web App. CGI interface is deprecated, and Mongrel, Thin, Unicorn, FastCGI gems (which are the usual suspects :)) are not built for our plateform. After spending some days trying, i resign myself using Webrick (which is not intended for production use, but for development, anyways it's working out of the box).

Using Webrick, our ruby webapp will run standalone, accessible via http port 3000. If you want to use Apache to access it (because you cant access port 3000 from the outside, because you need secured transations) you'll need to set 'reverse proxying' to map one of your Apache web directory (https://diskstation/redmine/ ) to Webrick server.

The most important about this installation is these references
(choose the 'root install' way)
(in french, use a dedicated redmine user which complicates things a little)
(Redmine official install howto)
(and finally to connect the running instance with Apache)

To write it again, the steps are:

  Setup MySQL (no other backend look usable right now)

    Activate MySQL services with Synology Console
    Create a 'redmine' database in MySQL (via phpmyadmin)
(unzip phpmyadmin into shared web. copy phpmyadmin\config.sample.inc.php into config.inc.php, and add these ''. then flag it as read only.
go on http://diskstation/phpmyadmin
  in privileges:
    create user in mysql db
    check 'create database for user + all credentials'
  Install 'Ruby and the gems'
ipkg install rubygems
  Install the right version of Rake and Rails (long process => coffee time):
gem install rails -v 2.3.5
gem install rack -v 1.0.1
  Plug Ruby with MySQL, using an adapter:
cd /tmp
check http://github.com/tmtm/ruby-mysql/downloads
wget http://github.com/downloads/tmtm/ruby-mysql/ruby-mysql-2.9.3-beta.tar.gz
tar -xzvf ruby-mysql-2.9.3-beta.tar.gz
cd ruby-mysql-2.9.3-beta/
ruby setup.rb
  Download and configure Redmine (http://www.redmine.org/wiki/redmine/RedmineInstall)
mkdir /volume1/apps/
cd /volume1/apps
wget http://rubyforge.org/frs/download.php/72201/redmine-1.0.1.tar.gz
tar -xzvf redmine-1.0.1.tar.gz
mv redmine-1.0.1 redmine
chown -R nobody:users redmine/
cp config/database.yml.sample config/database.yml
nano config/database.yml
(enter MySQL credential) 
  Session Key creation &  Database init
RAILS_ENV=production rake config/initializers/session_store.rb
RAILS_ENV=production rake db:migrate
  You should be able to launch Redmine from this point, with the command line.
ruby /volume1/apps/redmine/script/server -e production
   Create a startup script, daemonizing redmine:
nano /opt/etc/init.d/S97rubyrails.sh
  case "$1" in
     /opt/bin/ruby /volume1/rubyapps/redmine/script/server webrick -d -e production
     killall ruby
     $0 stop
     sleep 1
     $0 start
     echo “usage: $0 { start | stop | restart}” &>2
     exit 1
don't forget to chmod 755 S97rubyrails.sh
  Now, you can access redmine via  http://synology:3000 .
But Let's go one step further by implementing a proxy within Apache. The proxy thing helps if you need access to your redmine setup through the default syno apache frontend: it makes sense when you're enforcing security with passwords (Apache style), or only want to open your 80 port in your firewall.

  Finally, Reverse Proxying with Apache:

    Add this to /usr/syno/apache/conf/httpd.conf-user
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module  modules/mod_proxy_http.so
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /redmine/
ProxyPassReverse /redmine/
Apache server restart
/usr/syno/etc.defaults/rc.d/S97apache-user.sh restart
  And finally the most important part: tell Redmine to prefix every url with a 'redmine/'when generating pages:
Add the following line at the end of your Redmine config/environment.rb
Redmine::Utils::relative_url_root = "/redmine"
  Done ! Hopefully. Access to redmine via http://synology.ip/redmine

  Final note: after some time on using RedMine, i wouldn't recommend using it on a low-end synology. As an example, my DS-107+ really takes age at updating project wiki pages. In fact, i ended using the NAS as a gateway between the outside, and some other private servers running on my private network... Next post should about this.


Anonymous said...

you made a spelling mistake.

it should be ProxyPerserveHost -> ProxyPreserveHost

Nicolas said...


Thanks for this great tuto !

When I try to restart the apache (/usr/syno/etc.defaults/rc.d/S97apache-user.sh restart), I've this error :

Invalid ProxyPass|ProxyPassMatch parameter. Parameter must be in the form 'key=value'.

Any idea about what is going wrong ?

Btw, why do we need apache and reverse proxy for ?


Nicolas said...

Okay I found why :

I've put the line

ProxyPass /redmine/ /redmine/

instead of (in 2 lines)

ProxyPass /redmine/
ProxyPassReverse /redmine/

Ash said...

Thank you guys, i corrected my post, and added information concerning the proxy thing :)

Nicolas said...

It's working correctly now for the apache stuff ... but there is one problem now, when I reboot the synology, apache doesn't start (I can't connect to the administration console too)

if I run in ssh

/usr/syno/etc.defaults/rc.d/S97apache-user.sh restart

everything is fine after

Start User Apache Server .....
/usr/syno/etc.defaults/rc.d/S97apache-user.sh: user httpd started

But do you know why apache doesn't start automatically now ?

Nicolas said...

After a second reboot it seems to work great ... wait and see !

Thanks again for this great post

Chris said...
This comment has been removed by the author.
Chris said...

Great tutorial - unfortunately I couldn't get it to work as ipkg install rubygems now installs ruby 1.9 which isn't supported by RoR, meaning I'd need to compile 1.8.7 myself. Don't suppose anyone knows of archives of old versions compiled for Synology units? :)


Actually I'm really interesting making a webserver with readmine on syslogy ds212j, I inquried of you as i know syslogy product take a command in GUI, but this article says that we sould it setup by meself liken linux console,
So where is it happen to setting it up as you were written ?
Linux Console or syslogy builtin conolse ???

Thanks in advance for replying ?


francois said...

Hi !

thanks for the comment ; installing redmine on a sinology nas when you're not a command-line genius is quite an adventure, and your tuto was most helpful in solving the errors I had when I browsed the pages you link as reference.

However, I have an error when I type RAILS_ENV=production rake config/initializers/session_store.rb

Here's what I get :

(in /volume1/apps/redmine)
rake aborted!
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
/volume1/apps/redmine/Rakefile:8:in `require'
/volume1/apps/redmine/Rakefile:8:in `'
(See full trace by running task with --trace)


Does anyone have an Idea about what I should do to fix this ?