Redmine doesn't work properly in Apache - ruby-on-rails

I'm trying to get Redmine (a Ruby on Rails app) working. It works fine when started with ruby script/server webrick -e production, however, I'm having trouble getting it working in Apache with Passenger.
Accessing http://example.com/redmine returns the Redmine home page, but clicking any link (or even adding a / to the URL) results in a 404. According to the Rails log, a RoutingError occurs. For example, when opening the projects page: ActionController::RoutingError (No route matches "/projects.html" with {:method=>:get})
The Redmine directory is /var/www/localhost/htapps/redmine. I followed the documentation at http://www.modrails.org/documentation/Users%20guide.html#_deploying_a_ruby_on_rails_application (section 3.2), so there's a symlink at /var/www/localhost/htdocs/redmine pointing to ../htapps/redmine/public, and the Apache configuration contains DocumentRoot /var/www/localhost/htdocs and RailsBaseURI /redmine.
What is causing it to raise these RoutingErrors?

It looks like this issue was actually caused by the default .htaccess included with Redmine.
Redmine's .htaccess rewrites every request to end with .html. Redmine's routes expect .html-less requests.
Setting RewriteEngine to Off solved the issue for me.

http://ptspts.blogspot.com/2009/05/how-to-fix-railsbaseuri-sub-uri-with.html
The manual workaround (according to what is suggested on the pages above) is adding the line below to config/environments/production.rb:
config.action_controller.relative_url_root = '/redmine'

If not deploying to a Sub-URI and deploying using passenger, adding the rule RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] to your public/.htaccess also solves the issue. As that rule is IfModule-ed out in the default .htaccess.
Another option is to delete .htaccess if you're not using it (As an example you may be using it for additional layer authentication with AuthType Digest etc). It is not required when deploying with passenger.

Even if you will manage to run Redmine in suburi, redmine still will have issues.
Some pages won't be parsed and displayed correctly, if displayed at all.
This issue is almost one year old and indicated for next minor release. Btw dozen minor releases came out, but it's not yet fixed. FCGI mode does not support sub-URI.

Related

Rails 3.2 Asset Pipeline with Thin and Apache, not finding assets

My question is similar to this one Rails 3.2 Asset Pipeline with Passenger Endless Errors except that when I try to actually go to
<link href="/assets/application-eed7996ee9017637f923133371ab3e92.css" media="all" rel="stylesheet" type="text/css" />
I get a 404. Here's the thing I don't understand. It is looking in /assets/, but when I look at the code that was deployed, the assets are only in /public/assets, which is actually a symlink to /var/www/myapp/shared/assets. So what in the world is responsible for telling the app that looking in /assets will produce correct results??
I am using Rails 3.2.0, ruby-1.9.3-p125, deploying to Ubuntu, Apache, and Thin.
I should clarify: My assets are indeed deployed to the server. Everything works perfectly fine until they need to be served, in which case production.log tells me it's looking for them in /assets/application-eed7996ee9017637f923133371ab3e92.css, which 404's.
For every request my thin.log says
cache: [GET /] miss
and production.log says
ActionController::RoutingError (No route matches [GET] "/assets/application-abecf2e096af9ee80697fd49e79a55e7.js"):
UPDATE
#Brandan thanks for the help. My assets are indeed in RAILS_ROOT/public/assets. I put this in my Apache vhost file:
DocumentRoot /var/rails/myappname/current/public
RewriteEngine On
XSendFile On
XSendFilePath /var/rails/myappname #not even sure if this line is needed
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
My RAILS_ROOT/config/environments/production.rb settings:
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
Delete the following lines from your Apache configuration.
ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/
The answer came from In Rails, should I enable serve_static_assets?.
Typically, your assets should only exist in /public/assets for a deployed application.
Apache should be configured so that its DocumentRoot is your RAILS_ROOT/public. Then it will serve http://example.com/assets/whatever.css from RAILS_ROOT/public/assets/whatever.css, and it never goes through Rails for static assets.
Have you restarted your application since you precompiled your assets? Sometimes Rails is expecting an older/newer compiled version of your assets than is currently deployed.
I've been having this problem for days now. Thought it was an issue with capistrano or the ruby version however I'm pretty sure it's permissions related too.
My configuration was pretty much the same as yours although I'm also using Unicorn.
Here's what I did to sort:
Temporarily remove the following section because I think that was causing problems with the troubleshooting:
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
Perhaps get it all working and then add it back in. I don't think it's the cause of the problems however, when diagnosing things like this, it's best to remove as much as you can to find the culprit.
Run a chown -R xxx.xxx (replace xxx with your application user or web user) on the public directory. As soon as I did so, the css appeared again.
(What I did but maybe not essential) You might also want to install locally without cap. just in case there's an issue with it. That also worked for me.
Completely wipeout tmp/cache and public/* just in case.
Restart your apache server a couple of times.
You can see a gist of my conf. here
Try removing the ProxyPass and ProxyPassReverse directives from your apache/thin configuration. The P flag in your rewrite rule is already performing the proxy pass that you desire.
See http://httpd.apache.org/docs/2.0/mod/mod_proxy.html for more information.
Passanger knows its a RoR application as there is a config.ru file.
The same error you are reporting happened to me due to wrong permissions. Apache was not able to serve the files inside assets, but was able to send the files on public/
In my case I use capistrano so assets was a symlink to shared/public/assets.
what I did was:
chmod -R o+x shared/
x permissions are required to list and access directories. After that it worked. You have to make sure that assets has +x for others

Root of rails application serves wrong kind of file

I am using Ruby on Rails on a CentOS-server with apache 2.0. But somehow the root of the website does not load. It comes up as a download, with the right contents. But it needs to be server as html. Other links within the site are working fine (by adding a text/html type to the .htaccess). Also, when accessing the mongrel directly root does come up. Or when i put a index.html in the public folder of the rails app, it gets loaded as well.
My .htaccess:
DefaultType text/html # added for the other pages to get them working, like /products
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule .* "http://127.0.0.1:12001%{REQUEST_URI}" [P,QSA,L]
Rails version: 2.3.8
Mongrel version: 1.1.5
Apache version: 2.0.63
Due to a bug in mongrel_start, it wasn't working properly. This fixed the problem. Hope it can be a help for someone else in the future as well.

Ruby and Apache

I followed these instructions, installed passenger, but the web page is still not resolving to the ruby app. It just shows the files. Please help!
https://github.com/redbooth/teambox/wiki/installing-on-ubuntu
By "Ruby app", I assume you refer to an app built with Ruby on Rails, the most common Ruby web application framework.
Make sure that you set the web root to the /public directory, your PassengerRoot and PassengerRuby lines are in the right file (bear in mind that you should not copy those, but instead what the installer told you!), and that you included the RailsEnv line in your site's configuration. (If you are on Rails 3, use RackEnv, instead.)
But these are just generic tips for likely issues. It helps if you have some more specific error messages, if any exist...

Resource mapping works locally but not on webserver

Edit:
Well maybe this can give a clue. When created a Rails app in cPanel on my web host, in order to access the app you need to create a rewrite rule. Which I did, but didn't know what it did. I tracked it down to it creating the following 2 files:
home/mydomain/public_html/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]
and
home/mydomain/.cpanel/ruby-on-rails-rewrites.db:
appname: helloworld
domain: mydomain.com
port: 12030
rewritebasepath: /home/mydomain/public_html
url:
It seems that the root URL gets sent to Rails, but any other URL does not and I get an Apache 404 (not a Rails 404). Is there something wrong in the .htaccess file?
Is the rewrite condition only for the domain root? If it is, how can I make it for any URL ?
Original post:
I'm trying to deploy a rails website that works fine locally but not on the web server.
The rails app starts fine and I can access the home page. But any other link results in a 404.
My home page is set from within routes.rb like so:
map.root :controller => "home"
I am using RESTful routes and it works fine locally. In routes.rb all I have is a bunch of
map.resources :posts
map.resources :images
...
If I change the map.root to another controller (i.e map.root :controller => "posts", then that single page will display fine as well, and all other links will return 404s, including the one that previously worked when it was the one referenced in map.root.
This is my first rails deployment so it might be me doing something wrong. My web host tech support told me it's a coding issue and that they can't help me.
My website directory structure online is like so:
/home/mydomain/etc/rails_apps/mysitedir/ <- rails folders (app, config, db, ...)
/home/mydomain/public_html/ <- nothing here
Also, the files that are in my rails public folder, do they need to stay in that folder or should they be put in the public_html folder on the web? Because right now they're not found either. If I put them in the public_html folder though, they are found from the home page (javascript and css and images).
In my error log in cPanel, it shows errors like:
[Mon Oct 05 08:19:41 2009] [error] [client XX.XX.XX.XX]
File does not exist: /home/mydomain/public_html/market,
referer: http://www.mydomain.com/
Where market is one of the links I'm trying to access from my home page, for example, and it's one of my controllers.
In short, the only location I can access is the root.
What am I doing wrong that I am getting all these 404s?
I do not have shell access, all I have is cPanel. This is with Ruby 1.8.5 and Rails 2.3.4, the (shared) web server is Linux + Apache 2.2.11 (Unix).
You need to get your web root to point to /home/mydomain/etc/rails_apps/mysitedir/public/ Maybe this can be configured in cpanel?
If you can get access the shell you would do something like(syntax may vary slightly):
ln -s /home/mydomain/etc/rails_apps/mysitedir/public/ /home/mydomain/public_html
Note that you need to remove public_html first, you should verify that there are no negative consequences of this.
The problem is with my web host. Still hasn't been resolved by them.
I came across the exact same problem and found a fix. In the .htaccess file, remove that first '$' so you have:
RewriteRule ^/? "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]
That first bit is a Regex, so the $ matches the end of the URL.
As a side-rant, this is the umpteenth problem I've had to solve today because cPanel sucks.

Apache minimum version for Phusion Passenger

Our current Apache installations are running Apache 2.0. Now we'd like to add some Rails applications and plan to run them on Apache with Phusion Passenger. I've gotten conflicting reports about whether we need to upgrade Apache to 2.2 in order to use Passenger (a consultant I highly respect recommended that; someone from Phusion says 2.0 should be fine.
Anybody running Passenger with Apache 2.0 in production?
I was under the impression that the minimum version for Apache with Passenger was 2.2, but if you head over to their site and look in the Users Guide I'm sure it will say what you need.
i was choose this way. (optional)
im havent using Pasenger when production, i get simple deploy rails now. only create rails app # etc/rails_app/myapp/ and upload all app folder and public to myapp/app. then i just need to unchecklist # environment for production and configurated at database.yml
then i copied public # http/public_html folder
run mongrel -> rewrite 12007 to 80 -> restart mongrel
if u get problem, ur app only apper in index, and get error when link to another page.
only ask to admin host to configur .httaccess
for example like
RewriteEngine on
RewriteCond %{HTTP_HOST} ^myapp.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.myapp.com$
RewriteRule ^.*$ "http\:\/\/127\.0\.0\.1\:12007%{REQUEST_URI}" [P,QSA,L]
or do like railsninja said :)
Since no one seems to have a definitive answer, I'm going to assume that the answer I was given by someone at Phusion is definitive. It's on Google Groups at http://groups.google.com/group/phusion-passenger/browse_thread/thread/789f4f6e8f1c542d.
He states that Apache 2.0 and up should be fine. (As it worked out, we were able to go with Apache 2.2 for this server, so the point was moot for us.)
You don't need 2.2. 2.0 works fine and if it doesn't it's considered a bug. That said 2.2 is probably better than 2.0 so regardless of the minimum supported version you should go for 2.2.

Resources