Tuesday, November 25, 2014

install rails and deploy to apache2 with assenger

1) install rbenv

2) install ruby
   rbenv install 2.2.0
3) add gem configuration at ~/.gemrc
#######
---
gem: --no-ri --no-rdoc
#######
4) gem update --system
5) gem install rails
5) gem install passenger
6) passenger-install-apache2-module
7) follow and paste the passenger configuration into /etc/apache2/apache2.conf at the end
########
LoadModule passenger_module /home/user/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /home/user/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/passenger-4.0.53
  PassengerDefaultRuby /home/user/.rbenv/versions/2.1.5/bin/ruby
</IfModule>

<VirtualHost *:80>
   ServerName www.hostname.com
   DocumentRoot /somewhere/public  
   <Directory /somewhere/public>
      # This relaxes Apache security settings.
      AllowOverride all
      # MultiViews must be turned off.
      Options -MultiViews
      # Uncomment this if you're on Apache >= 2.4:
      # Require all granted
   </Directory>
</VirtualHost>

#######
8) rails new demo
9) rails g scaffold User name pass age:integer dob:datetime
10) rake db:create:all
11) rake db:migrate RAILS_ENV=production
to start rails server at production then

12) rake assets:precompile RAILS_ENV=production
       add secret to production at config/secret.yml
        production:
          secret_key_base: 9c7...d4d

13) add   'config.serve_static_assets = true'  in config/environments/production.rb
13) add    root 'users#index'  into config/routes.rb
14) rails s -e production
browse at localhost:3000

procedure to deploy into apache2 
15) sudo ln -s /home/user/demo /var/www/demo
13) change   'config.serve_static_assets = false'  in config/environments/production.rb


15) sudo vim /etc/hosts
add  "127.0.0.1  www.myhost.com"

16) modify /etc/apache2/apache2.conf at the end
########
<VirtualHost *:80>
   ServerName www.myhost.com
   DocumentRoot /var/www/demo/public  
   <Directory /var/www/demo/public>
      # This relaxes Apache security settings.
      AllowOverride all
      # MultiViews must be turned off.
      Options -MultiViews
      # Uncomment this if you're on Apache >= 2.4:
      Require all granted
   </Directory>
</VirtualHost>
#######

17) restart the server  sudo /etc/init.d/apache2 restart


locate browser at www.myhost.com
then you should see the home , if not then check log/production.log file