Project

General

Profile

HowTo Install Redmine on subdirectory (sub-URI) on Apache » History » Version 1

Carlos Troncoso, 2012-04-02 08:19

1 1 Carlos Troncoso
h1. HowTo Install Redmine on subdirectory (sub-URI) on Apache
2
3
h2. Your Issue
4
5
You are probably running ruby 1.9, rails 3, apache, passenger and you want to run redmine.
6
Unfortunately, it's not _rails-3 ready_, and passenger can only run one ruby version.
7
So you've got two choices.
8
# relying on host header (@http://redmine.mydomain.com@)
9
# sub-URI deployment (@http://www.mydomain.com/redmine/@)
10
11
This tutorial will focus on choice 2. Sub-URI deployment.
12
13
h2. Dependencies
14
15
I'll assume you got redmine running stand-alone with mongrel or better even, with "Thin":http://code.macournoyer.com/thin/
16
17
h2. Roadmap.
18
19
# Change the base-uri of your stand-alone application.
20
# Proxy it through apache.
21
22
h2. Change the base-uri of your stand-alone application.
23
24
Quite simple actually.
25
Open up @config/environment.rb@ and add at the *very end of the file* the following line:
26
<pre>
27
Redmine::Utils::relative_url_root = "/redmine"
28
</pre> 
29
Of course, you can choose whatever subdirectory you want it to run.
30
31
If you try to test your app on localhost:3000/redmine, all your css an js will show up broken.
32
In my setup, the routes to the js and css were actually rewriten to point to /redmine/javascript and /redmine/stylesheets, but the problem is that... *the files aren't there!*. As they are served staticly over public/*, rails rewrite actually breaks them, but, that is exactly what we want.
33
Don't worry. It'll be fixed on the next step.
34
35
h2. Proxy it through apache.
36
37
Reverse proxy usually has two parts:
38
# redirecting a web request to other URI
39
# rewriting the returned HTML and header to match the sub-URI
40
41
On step N°1, a request to http://www.mydomain.com/redmine is sent to http://www.mydomain.com:5001
42
On step N°2, the HTML is rewritten to change any reference of http://www.mydomain.com:5001/ back to http://www.mydomain.com/redmine.
43
44
But as all url references are relative, we never see the http part on an rails html, just the "/wharever", and we already reference the sub-URI with the _relative_url_root_ line we added to @environment.rb@, so we can actually skip step N°2.
45
46
We just need to get redirected.
47
Assuming you are deploying to @/redmine@:
48
# add and enable a new _site_ called *redmine* on apache
49
# edit the file and fill it up with this
50
<pre>
51
<Proxy *>
52
  Order deny,allow
53
  Allow from all
54
</Proxy>
55
56
ProxyRequests Off
57
58
ProxyPass /redmine/ http://127.0.0.1:3000/
59
</pre>
60
# fire up your _Thin_ or _mongrel_ server. @thin start -e production -a 127.0.0.1 -p3000@
61
# restart apache @sudo apache2ctl graceful@
62
63
h2. Ready!
64
65
Just go open @http://www.mydomain.com/redmine/@ and you will be browsing your proxied redmine site.
66
*IMPORTANT: remember the trailing slash! 
67
@www.whatever.com/redmine/@ WORKS 
68
@www.whatever.com/redmine@ Won't work.*
69
As a workaround, just create a file called redmine.html on the the www root with a simple redirect.
70
i.e.:
71
<pre>
72
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
73
<html>
74
  <head>
75
    <title>Your Page Title</title>
76
    <meta http-equiv="REFRESH" content="3;url=/redmine/"></HEAD>
77
  <BODY>
78
   Redirecting in 3 seconds...
79
  </BODY>
80
</HTML>
81
82
</pre> 
83
84
Just change the 3 of the _content_ value to 0 if you want an instant redirect.
85
86
That's all folks. I hope it helped someone.