How to configure ruby on rails with Apache - ruby-on-rails

i have strugle in connection between J2me and ruby on rails under Webrick server...
dats why i need configure with apache..i saw some tutorials about configuring..but it's not working..

You need to install Phusion Passenger: http://www.modrails.com/
Also, for performance improvement, do install REE: http://www.rubyenterpriseedition.com/

What environment are you coming from? Unix, Mac, Windows? Let's assume you're using some Unix variant, as you should, and Apache2 is already properly installed:
1 - install phusion passenger:
$ gem install passenger
2 - install passenger-apache2-module:
$ passenger-install-apache2-module
Be sure to read what the passenger-install-apache2-module command output is telling you, in the end it will give you some lines you have to put in some apache configuration files, if you miss that, it won't work. At all.
3 - Edit your vhosts.conf file (under /etc/apache2/) to define a hostname for your application, point to your application's public folder, etc.
VirtualHost examples
4 - Profit.
Commands listed under 1. and 2. might need admin privileges, it all depends on how your environment is set.
WebRick is not for production environments at all, in fact, it's not really good for development either, if you intend on doing some slightly more complex stuff with your rails applications. Other than that, you didn't really give enough detail about your problem, so I hope this answer at least points you in the right direction.

Related

Why when outside the installation directory do I get passenger: command not found?

I have just built a RackSpace cloud server with Ubuntu 12 LTS and performed a "standard" Ruby on Rails installation. I created a user (bob) and added it to the sudu group.
I then logged out of root and logged in as bob. Then issued sudo su from the /home/bob directory. I then installed everything needed to run the Rails Application 'as root'.
I then installed the Rails code in /home/bob and passenger started up when I issued:
RAILS_ENV=production passenger start -p 3000
however, since I want to run multiple Rails applications on this server, I then created another directory /home/bob/newapp and installed Rails code there. (ideally I would want to put all the different Rails applications in their own subdirectory below /home/bob)
When I issue the command (shown below) from /home/bob/newapp
RAILS_ENV=production passenger start -p 3000
I get
passenger: command not found
why is passenger only accessible from /home/bob ?
NEWS: just discovered, passenger is 'available' until the moment I complete the edit of the content of /config/database.yml thus as long as I do NOT edit the database.yml file, passenger will start. After I edit database.yml the "passenger: command not found" appears. How bizarre is that?
SNAP: looks like when I installed passenger it used Ruby-2.1.1 however the old application wants ruby-1.9.3-p194. I need to figure out how to get passenger to run with ruby 1.9.3 or install a second version of passenger (???)
More News:
Thank you,Hongli, for your response. I followed your links/suggestion to read the passenger documentation. I had read it before without recognizing the needed information. This time I found the "magical" command:
rvm-exec ruby-version ruby -S (eg: rvm-exec ruby-1.9.3-p194 ruby -S )
this has turned out to be very helpful, although I did end up following a process which has resulted in two different version of passenger being installed.
Read the About environment variables section of the Phusion Passenger manual to learn what "command not found" errors are, why they occur, and what you can generally do about them.
In your case, entering /home/bob automatically makes RVM change your PATH to include a specific Ruby version's bin directory. Read the When the system has multiple Ruby interpreters section of the Phusion Passenger manual to learn how to deal with that.
The article Hongli suggested I read definitely moved me in the correct direction.
The use of: rvm-exec 'ruby-version' ruby -S allows me to get passenger started, provided a version of passenger has been installed using the version of ruby required by the Rails application.
Thus if I load up a Rails application built with ruby-1.9.3-p194, I will need a version of passenger installed with the same version of ruby.
If I load up another Rails application built with ruby-1.9.3-p286, I will need a version of passenger installed with that version of ruby.
Then starting each version of passenger can be accomplished with the rvm-exec command with the appropriate ruby version.
Perhaps there is a more elegant solution, but the above works for me.

How can I switch a production rails app (passenger/nginx/capistrano) to use RVM on Ubuntu?

I have a production app using passenger, nginx, and capistrano. I set it up without RVM (running ruby installed directly to the OS on Ubuntu without a version manager), but would like to switch over to using RVM so that I can upgrade ruby when I need to.
What steps do I need to take to install RVM and configure passenger/nginx/capistrano to use it?
The key here is that I already have the server running, and the downtime needs to be minimal / overnight since the app is being used in a production setting every day. I can't afford to mess up and have the app down for too long.
My best guess is that I'm going to need to modify my nginx config (sudo nano /opt/nginx/conf/nginx.conf) - and edit these lines: (?)
http {
passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19;
passenger_ruby /usr/local/bin/ruby;
Follow instruction on rvm.io to install rvm. However, you are strongly advised not to use it in production. A production setup should follow KISS principle. Every additional piece of software you install, will add a little bit of complexity to the setup. Given that all rvm does is to provide a set of handy commands to install ruby and change PATH variable, it is not an essential tool on production setup.
If all you need is ability to install new versions of ruby without messing things up, use ruby-install. This makes it easy to install ruby, but will not manipulate environment settings (such as PATH).
As you mentioned above, you are right, you should just change the pointer to ruby executable in nginx configuration to switch ruby version. In production mode, this does not stop/interrupt your running rails application until you restart nginx. So it is safe to install a new version of ruby in another folder (such as /usr/local/rubies/ruby-193-p448/ or /usr/local/rubies/ruby-200-p0/), change passenger_ruby in nginx settings to point to the new ruby, then restart nginx.
Also note that from Passenger 4.0.x onwards, you can use multiple versions of ruby with a single nginx/passenger combination, one to run passenger and another to your rails application using the passenger_ruby directive in http block and/or server block of nginx configuration.

Rails application running on Apache HTTPD

Is there a way to run Ruby on Rails app on Apache HTTPD (CentOS)?
Is this just a matter of setting up httpd.conf with VirtualHost?
Passenger is probably the easiest way to get that running. Here's a tutorial on installing Passenger on CentOS6, and here are prebuilt rpms.
http://rubyonrails.org/deploy
Check Rails site, I think you have to use a Proxy, unless I'm misunderstanding what you mean by HTTPD. Seems like you want a simple Apache setup, Rails should be able to help.
EDIT: James answer looks perfect. Same as mine, but he has real CENTOS tutorials... I've never used CENTOS, just done this through Ubuntu.
You can run mod_rails aka Passenger or a Mongrel Cluster or Thin Cluster.
I find passenger the easiest, you can download it Here
The Steps are quite easy
sudo gem install passenger
sudo passenger-install-apache2-module
Follow instructions on screen.

How can I get Phusion Passenger to use the correct version of Ruby? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
My colleague has a Rails development environment using Nginx, Phusion Passenger, and RVM. When he tries to load a project, the it complains that it requires a different version of Ruby than what is available:
The given ruby environment requires ruby-1.9.2-p290 (versus ree-1.8.7-2011.03) (RVM::IncompatibleRubyError)
We are switching from REE to MRI Ruby. Here's what I've checked so far:
.rvmrc in that directory is rvm use --create default#ourapp.
rvm list default returns ruby-1.9.2-p290
We've changed out and back into the directory and seen that it says it's using 1.9.2
The configuration file for nginx sets passenger_root and passenger_ruby correctly, as far as I can tell
Passenger has been compiled with Ruby 1.9.2.
Is there something else that I'm missing?
Try reading the documentation?
https://www.phusionpassenger.com/documentation_and_support#documentation
You use a wrapper by specifying --passenger for your rvm command and tell Apache or Nginx to use the wrapper it generates. Ruby isn't 'compiled in'.
This will only give you one rvm instance but it will work.
For multiple RVM's the only solution I've ever found to work is to use Unicorn and reverse proxy to the running unicorn processes. Unicorn scales properly and is a grown up unix citizen - it's what I use for production, personally.
EDIT - have just noticed that Passenger 3 is a bit more RVM-friendly (as given in the documentation above) - but you still have to run against a wrapper.
On a Mac, for dev, 37 Signals have an alternative called POW that allows easy config for dev environments.
Passenger has to be compiled with a specific version of Ruby and is locked in to that from that point forward. You can't just switch it around in RVM without also running through the passenger-install-X-module regimen.
If you really want to use different rubies and have RVM respected, use apache + unicorn. Install the mod_proxy and mod_rewrite modules for apache, set up unicorn_rails with a unicorn.conf and run 'unicorn_rails -E production -D -c config/unicorn.conf'. This is assuming you put the config for unicorn in the rails app's config directory.

How to run ruby on apache?

I'm very new to ruby and I can run ruby scripts on command line easily, but I want to output my script to a browser, not just using the command line.
Your help will be much appreciated, thanks.
Passenger is probably the easiest way to run Rails applications.
I'd recommend either Passenger or Unicorn, both of which are extremely popular in production environments. Passenger is typically easier to setup.
See this blog post:
"Install RVM, Passenger, Nginx and Rails 3 on Ubuntu Lucid Lynx". You can use WEBrick/Thin for development perhaps.

Resources