How to deploy Rails application on Apache Passenger on Ubuntu 14.04

1. sudo apt-get install ruby-full build-essential
2.  Install Ruby and Rails
Install by RVM:
curl -L https://get.rvm.io | bash -s stable --ruby --rails
run
source /home/ubuntu/.rvm/scripts/rvm
run
rvm requirements 
 or install by package:
wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
tar xvzf rubygems-1.3.4.tgz
cd rubygems-1.3.4
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem 
sudo gem update --system


3. Install Apache
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev

4. Install Mysql
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient15-dev
sudo gem install mysql


5. Install Phusion Passenger
sudo gem install passenger
sudo passenger-install-apache2-module


After successful run of command sudo passenger-install-apache2-module, there should display message:
   LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.50/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.50
     PassengerDefaultRuby /usr/bin/ruby1.9.1
   </IfModule>


Copy and paster these lines into /etc/apache2/apache2.conf file

6. sudo a2enmod rewrite
7. Now create sample app on Rails
rails new demo
bundle install
8. Create new file demo.conf in /etc/apache2/sites-available/demo.conf
<VirtualHost *>
    # Change these 3 lines to suit your project
    RailsEnv development
    ServerName demo.local
    DocumentRoot /home/user/demo/public # this is your app's public dir path
    <Directory /home/user/demo/public>
    Require all granted
    Options FollowSymLinks
    # This relaxes Apache security settings.
    AllowOverride None
    # MultiViews must be turned off.
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

9. add following line into host file in /etc/hosts
127.0.0.1      demo.local
10. enable demo.conf by:
sudo a2ensite demo.conf

11. sudo service apache2 restart

Comments