Wednesday, May 12, 2010

Rails :: Apache :: Passenger

Given
- Apache installed
- Rails installed

Rails work independently with Mongrel and can be executed
$ rails server
web address- localhost:3000

To connect apache with Rails we need passenger.

Steps to install passenger
$ sudo gem update
$ sudo gem install passenger
$ sudo passenger-install-apache2-module


ERROR:
If 'sudo gem install passenger' gives an error saying,  "Failed to build gem native extension."
then $ sudo apt-get install ruby1.8-dev
and rerun the install 


This gave me an error
sudo: passenger-install-apache2-module: command not found
Reason: i didnt’t have the gems bin directory in my PATH so do this instead
$ sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module


Press enter after reading information.
It should end with something like this
--------------------------------------------
The Apache 2 module was successfully installed.


Please edit your Apache configuration file, and add these lines:


   LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
   PassengerRoot /var/lib/gems/1.8/gems/passenger-2.2.11
   PassengerRuby /usr/bin/ruby1.8


After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!


Press ENTER to continue.
--------------------------------------------


After you press enter, it gives details on how to use Apache to direct it to the Rails files.
--------------------------------------------
Deploying a Ruby on Rails application: an example


Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:


   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <Directory /somewhere/public>
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </Directory>
   </VirtualHost>


And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:


  /var/lib/gems/1.8/gems/passenger-2.2.11/doc/Users guide Apache.html
--------------------------------------------

This finishes the passenger setup.
Edit the file
$ sudo vim /etc/apache2/apache2.conf
At the bottom of the file copy paste the 3 lines.

Restart the apache server
$ sudo /etc/init.d/apache2 restart

To check if the passenger is working
$ sudo /var/lib/gems/1.8/bin/passenger-status
----------- General information -----------
max      = 6
count    = 0
active   = 0
inactive = 0
Waiting on global queue: 0

----------- Domains -----------

To set the Rails folder
Enter
Alias Rails_application /path/to/application
in the /etc/apache2/sites-available/default to point to the public folder in the rails application folder, where Rails_application is the name is the Rails application.

Now access the website using
localhost/<rails_application>

No comments:

Post a Comment