Deploying Ruby on Rails application with Ruby 1.9.1 + Rails 3 + Apache MPM + Phusion Passenger on ubuntu

The first thing we’ll want to do is make sure your ubuntu version is up to date by running following command on terminal

sudo apt-get update

After this, we’ll be installing some software that need to be built so we’ll need to get packages required for compiling. With ubuntu, you can type this single command and get everything you need:

sudo apt-get install build-essential

Once you have got his tools, its time to install Ruby and MySQL, Enter following commands to install ruby and MySQL

Get the ruby 1.9.1 version in .tar.gz format, extract it on your local machine and follow the following steps:

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.gz

Extract the tar and run the configure, make and make install commands as follows:

tar -xvf ruby-1.9.2-p0.tar.gz
./configure
make
make install

This will install ruby 1.9.2, you can confirm this by running:

ruby -v
sudo apt-get install libmysql-ruby mysql-client-5.1 mysql-common mysql-server-5.1 libopenssl-ruby

Additional packages for production for improving performance

sudo apt-get install libc6 libpcre3 libpcre3-dev libpcrecpp0 libssl0.9.8 libssl-dev zlib1g zlib1g-dev lsb-base

Ready to install rails now with the following command:

gem install rails -v=3.0.3 --no-ri --no-rdoc

Now, its time to install Apache + Passenger:

Get the apache from this link http://httpd.apache.org/download.cgi#apache20

tar -xvf httpd-2.2.19.tar.gz

Change directory to httpd-2.2.19 and execute following command

./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate --enable-proxy --enable-proxy-balancer --enable-proxy-http --enable-rewrite --enable-cache --enable-mem-cache --enable-ssl --enable-headers --with-mpm=worker
make
make install
make clean
ln /usr/local/apache2/bin/httpd /usr/local/bin/

Install Passenger:

gem install passenger-3.0.2.gem -l --no-ri --no-rdoc

Now, configure Apache and Passenger:

sudo passenger-install-apache2-module

some of the packages are missing (required for above command) install them

apt-get install libcurl4-openssl-dev
apt-get install apache2-prefork-dev
apt-get install libapr1-dev
apt-get install libaprutil1-dev
apt-get install apache2-mpm-worker

The Apache 2 module was successfully installed with Passenger.

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

LoadModule passenger_module /usr/lib/ruby/gems/1.9/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.9/gems/passenger-3.0.2
PassengerRuby /usr/bin/ruby1.9

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!

Troubleshooting and other useful information: /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/doc/Users guide Apache.html

Deploying a Ruby on Rails application:

Create application “myapp” in /var/www

Set the configurations for myapp

vim /etc/apache2/sites-enabled/myapp


#    ServerAdmin webmaster@dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/_travel_error_log"
    CustomLog "logs/travel_access_log" common

      ServerName ip_address
      DocumentRoot "/var/www/myapp/public"
      RailsEnv production
      
         PassengerEnabled on
          PassengerMinInstances 3
         Options Indexes FollowSymLinks
          Order allow,deny
          Allow from all
      

Now, let’s disable the default site, and enable the myapp site.

sudo a2dissite default
sudo a2ensite myapp

Leave a comment