Saturday 20 April 2013

ROR installation through RVM, along with passenger

Assumption:
I assume you have apache2 installed and working on your system/server.

Installtion instruction:
  1. Install rvm
  2. Install ruby with rvm and then install gems: Rails
  3. Install Passenger and passenger apache module
  4. Configure apache2
  5. Learn to create virtualhost settings for your every rails application

Installation of RVM and Ruby

Install rvm with ruby


        $ \curl -#L https://get.rvm.io | bash -s stable --autolibs=3 --ruby

Add rvm path to your shell
         echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
         source ~/.rvm/scripts/rvm

Check rvm for existing ruby's versions
      $  rvm list known
Check for install ruby version
       ruby -v
Set default ruby version
       user$ rvm use 1.9.2 --default


Installation of passenger and apache passenger module

gem install passenger
$ sudo passenger-install-apache2-module

Now, simply Follow instructions on your screen

You might face this error, while installing  passenger-install-apache2-module
--------------------------------------------
Compiling and installing Apache 2 module...
cd /home/krishna/.rvm/gems/ruby-2.0.0-p0/gems/passenger-3.0.19
/home/krishna/.rvm/wrappers/ruby-2.0.0-p0/rake apache2:clean apache2 RELEASE=yes
# /home/krishna/.rvm/wrappers/ruby-2.0.0-p0/rake apache2:clean apache2 RELEASE=yes
rake aborted!
cannot load such file -- rubygems/builder
/home/krishna/.rvm/gems/ruby-2.0.0-p0/gems/passenger-3.0.19/build/gempackagetask.rb:12:in `<top (required)>'
/home/krishna/.rvm/gems/ruby-2.0.0-p0/gems/passenger-3.0.19/build/basics.rb:41:in `<top (required)>'

Then try updated version of passenger
   $ gem install passenger --version 4.0.0.rc6
 $ passenger-install-apache2-module

Now, pay special attention to the lines it shows in the end.

   LoadModule passenger_module /home/krishna/.rvm/gems/ruby-2.0.0-p0/gems/passenger-4.0.0.rc6/libout/apache2/mod_passenger.so
   PassengerRoot /home/krishna/.rvm/gems/ruby-2.0.0-p0/gems/passenger-4.0.0.rc6
   PassengerDefaultRuby /home/krishna/.rvm/wrappers/ruby-2.0.0-p0/ruby

They are the statements to be added in apache2.conf file.

But i don't prefer  to taint mine apche2.conf file. Instead why don't we create separate file and enable them?

After successful installation of the Apache 2 module, follow the next set of step to configure Apache.
Create the following two files in /etc/apache2/mods-available

mkdir /etc/apache2/mods-available/passenger.load
paste following code in passenger.load file
LoadModule passenger_module /home/krishna/.rvm/gems/ruby-2.0.0-p0/gems/passenger-4.0.0.rc6/libout/apache2/mod_passenger.so

     mkdir /etc/apache2/mods-available/passenger.conf
paste following code in passenger.conf file
PassengerRoot /home/krishna/.rvm/gems/ruby-2.0.0-p0/gems/passenger-4.0.0.rc6
        PassengerDefaultRuby /home/krishna/.rvm/wrappers/ruby-2.0.0-p0/ruby

Enable the modules by creating the following symbolic links in /etc/apache2/mods-enabled

$ ln -s /etc/apache2/mods-available/passenger.load /etc/apache2/mods-enabled/passenger.load
$ ln -s /etc/apache2/mods-available/passenger.conf /etc/apache2/mods-enabled/passenger.conf

Restart apache:
        sudo /etc/init.d/apache2 restart

Now, to create new rails application
       create your rails application
   eg  
          $ cd /home/ror
        $  rails new my_app.com
   
Now, attach this application to your server. In this case, Apache2
Create new file  inside /etc/apach2/sites-available/my_app.conf

<VirtualHost *:8092>
 Options +Indexes
 ServerAdmin my_app.com
 ServerName my_app.com

 DocumentRoot /home/ror/my_app.com/public

 <Directory /home/ror/my_app.com/public>
 Options Indexes FollowSymLinks
 AllowOverride All
 Order allow,deny
 Allow from all
 Options -MultiViews
 </Directory>

 RailsEnv production
</VirtualHost>


If you are using rails version >3 ,  then your configuration should be like this:


<VirtualHost *:8092>
        ServerName  my_app.com
        DocumentRoot /home/ror/my_app.com/public
        <Directory /home/ror/my_app.com/public>
                 Options Indexes FollowSymLinks
                 # This relaxes Apache security settings.
                 AllowOverride all
                 Allow from all
                 # MultiViews must be turned off.
                 Options -MultiViews
        </Directory>
        #if you have app in a subdirectory, then add baseuri and it's absolute to configuration using RackBaseURI
        RackBaseURI  /myapp
        RackEnv production
        PassengerEnabled on
        PassengerMinInstances 3
        <Directory /home/ror/my_app.com/public/myapp>
                Options -MultiViews
        </Directory>
</VirtualHost>


Add port number to your httpd.conf file
  Listen 8092


To enable this site, symlink it to sites-enabled
        cd /etc/apache2/sites-enabled
        ln -s ../sites-available/my_app.conf  my_app.conf
OR 
 Use apache commands( Good Way): 
     sudo a2ensite my_app.conf
     sudo /etc/init.d/apache2 restart


Reload 
       $ sudo /etc/init.d/apache2  reload
Restart apache: 
        $ sudo /etc/init.d/apache2 restart
Check your vhost entry by dumping vhosts
       $  apache2ctl -S




References:
  1. http://stackoverflow.com/questions/7159851/setting-up-passenger-phusion-on-ubuntu-11-04
  2. http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri

No comments:

Post a Comment