Rails 3:Deploy Rails 3 Application in Apache Server on Windows Machine? - ruby-on-rails

I have a Rails Application which runs on "thin" Server on Windows Machine. I heard the best Server for Rails is Phusion Passenger,but unfortunately my Server runs on Windows Machine and it is not possible to install Phusion Passenger in windows.
Is it possible to deploy my Rails Application in Apache Server. If possible will it effect the performance of my Rails Application.
Any Help is appreciated.

You can use apache to reverse proxy requests to the thin server. The apache configuration directives look a little like this (you will probably need to change these)
DocumentRoot /path/to/rails/public
<Location /assets >
ProxyPass !
</Location>
ProxyRequests Off
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
Replace 3000 with the port you set thin to run on.

Related

What have I done wrong in setting up Passenger/mod_rails?

I am attempting to get a Rails development environment up using a CentOS virtual machine. It will run Apache with Phusion Passenger, and I will access it from the host OS by entering the VM's LAN IP (eg 192.168.0.5).
I have been able to run Rails apps perfectly using WEBrick, and I have been able to serve static pages and PHP perfectly from Apache. But getting Passenger set up is proving to be a baffling nightmare of endless problems for me, and I would absolutely love some help from someone who knows what they're doing here.
So here's what I've done.
Booted into a fresh CentOS 6.3 machine. Using yum, installed httpd (Apache 2.2), sqlite-devel, all the other good stuff you need.
Installed RVM (to /home/vagrant/.rvm/), and Ruby 2.1.2, which I can confirm is working perfectly.
Installed Passenger with rvmsudo passenger-install-apache2-module.
Added the following to my httpd.conf.
.
LoadModule passenger_module /home/vagrant/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so
<IfModule module_passenger.c>
PassengerRoot /home/vagrant/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.45
PassengerDefaultRuby /home/vagrant/.rvm/gems/ruby-2.1.2/wrappers/ruby
</IfModule>
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/dangerzone/public
<Directory /var/www/html/dangerzone/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Finally, in /var/www/html, I executed rails new dangerzone to create the app.
Initially, trying to access my app gave me a Passenger error 'no JS runtime', which thrilled me because I'd spent 5 or so hours trying to get Passenger recognised at all. I installed Node-JS through Yum, and my current error is a 500, Internal server error.
I see nothing in /etc/httpd/logs/error_log.
I've followed the instructions on the RVM and Passenger websites to a letter. I've Googled this problem until I'd read the entire top 30 results. I've wiped the VM and started from scratch in case I did something wrong -- same problem. So I'm kind of baffled. Have I screwed up something really obvious?

what is the relationship between rails Phusion Passenger apache?

I know rails is the ruby framework and apache is the server of rails.While what is Phusion Passenger used for? Is it a server or a deploy tool?
Now I am trying to deploy my rails app on the server,while I don`t know how to use Phusion Passenger and apache to get my app running ):
thanks in advance
Phusion Passenger is just an apache mod that needs to be activated in the virtual host your application is using, telling apache which version of Rails is used and other configurations like this one. So basically, Apache uses Passenger to run Ruby on Rails applications.
You have to read this in order to install Passenger : https://www.phusionpassenger.com/download (just scrool down a little to read the open source version documentation).
And this in order to set it up and run it for one of your applications : http://www.modrails.com/documentation/Users%20guide%20Apache.html#_configuring_phusion_passenger So, yeah, a lot of text in here but you don't need to read everything fortunately.
Besides, when you install it, Passenger will tell you exactly what to write in your Virtual Host configuration and basically, there are only 2 lines of text. : )
Most of the time, if you have a virtual Host that looks like so :
<VirtualHost *:80>
ServerName www.wsgiapp.com
DocumentRoot /webapps/wsgiapp/public
<Directory /webapps/wsgiapp/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Passenger will tell you to write something like this once installed :
<VirtualHost *:80>
ServerName www.wsgiapp.com
DocumentRoot /webapps/wsgiapp/public
PassengerRuby /usr/bin/ruby
PassengerRoot /somewhere/passenger/x.x.x
<Directory /webapps/wsgiapp/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

RoR use url w/o port 3000?

What's the easiest way to point domain.com to my RoR app? When I don't include the port, ie domain.com:3000 it lists the directory.
If you are using apache, you need to use a rails mod to get it working. The best one is Phusion Passenger. It is very easy to set up, follow their directions, set up your virtual host and you'll be on your way. Again, apache cannot serve rails apps without extra additions.
It sounds like you are getting the mongrel/webrick servers that you run with ruby script/server or rails server confused with apache. In production don't even bother with webrick or mongrel if you've got apache running. Install Passenger. Then its easy, just go to your conf file and add your VirtualHost.
<VirtualHost *:80>
ServerName www.domain.com
DocumentRoot /webapps/mysite/public
<Directory /webapps/mysite/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

Apache server restart with Ruby on Rails

I have just restarted my apache server which is running ruby on rails. Now it isn't serving any web pages because I think that some of the Rails related services are not working.
Does anyone know how to sort this out? Any help greatly appreciated.
More info: error says "Ruby on Rails application could not be started" with Phusion Passenger on the front page.
The application was working before the restart and I have changed some javascript on one of the ruby generated html pages. No major config changes.
Are you sure you have it setup properly? If it only started failing after a restart, chances are you made a bad change to your config. Here's a sample configuration (/etc/apache2/sites-available/site):
<VirtualHost *:80>
ServerName www.site.com
DocumentRoot /var/rails/site/public
<Directory /var/rails/site/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Make sure apache has access to your app's folder. Usually, apache runs as www-data.
Guys - thanks for all of the feedback. You don't need to restart apache Web server , you just need to do following steps to restart passenger
cd /home/veriqual/r2/
touch tmp/restart.txt
Hope this helps people.

How do I configure Apache 2.2 for Ruby on Rails in Windows?

I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails.
Does anyone know of a good, current tutorial for configuring Apache 2.2 for Ruby on Rails apps?
EDIT: At least until there's a Phusion Passenger for Win, Apache + Mongrel is the way to go. You can use Apache + FastCGI without Mongrel, but under real loads you will get (more) zombie processes and (more) memory leaks.
You could also look at proxying to Thin in the same way as detailed below. However, I've had some instabilities with Thin on Win, even though it's appreciably quicker. AB (Apache Benchmark) is your friend here!
Configuring Apache + Mongrel on Windows is not significantly different from *nix.
Essentially, you need to proxy requests coming into Apache to Mongrel. What this boils down to is something like this:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost localhost:80>
ServerName www.myapp.comm
DocumentRoot "C:/web/myapp/public"
ProxyPass / http://www.myapp.com:3000/
ProxyPassReverse / http://www.myapp.com:3000/
ProxyPreserveHost On
</VirtualHost>
Stick this in your httpd.conf (or httpd-vhost.conf if you're including it).
It assumes you're going to run mongrel on port 3000, your Rails root is in C:\web\myapp, and you'll access the app at www.myapp.com.
To run the rails app in production mode:
mongrel_rails start -p 3000 -e production
And away you go (actually mongrel defaults to port 3000 so you could skip -p 3000 if you want).
The main difference is that you cannot daemonize mongrel on Windows (i.e. make it run in the background). Instead you can install it as a service using the mongrel_service gem.
Also, running a cluster is more complicated and you won't be able to use Capistrano. Let me know if you want more info.
I'm new to RoR and have been attempting the same thing on Windows Server 2008, here are some additional notes on getting mongrel going as a service:
if you get compilation errors when installing mongrel_service:
gem install mongrel_service
try using a binary instead by specifying your platform:
gem install mongrel_service --platform x86-mswin32
Additionally, to actually install the service you need to run this command in your RoR's app directory:
mongrel_rails service::install --name MyApp -e production -p 3001 -a 0.0.0.0
(or to remove:
mongrel_rails service::remove --name MyApp
)
Then you should be able to start/stop the app "MyApp" in your windows services control panel.
Hope that helps someone.
At the moment Mongrel does not work properly with Ruby 1.9 and will throw a "msvcrt-ruby18.dll not found" error when executing the command mongrel_rails.
Thin in this case seems to be the only option for now.
I just wanted to add this article to the list. It explains how to have Apache serve ruby files without the need to install any other applications.
http://editrocket.com/articles/ruby_apache_windows.html
You might want to try Bitnami RubyStack

Resources