Monday, January 2, 2012

Creating a Production Rails 3.1 Server (Ubuntu 10.04 LTS)

The following are instructions on how to create a production Rails 3.1 Server using Ubuntu 10.04 LTS

Download the Ubuntu 10.04.3 LTS 64 bit Server ISO from here and install it. Install the "LAMP Server" and "OpenSSH Server" packages when prompted.
Install prerequisites
sudo apt-get install build-essential libyaml-dev zlib1g-dev libcurl4-openssl-dev libssl-dev libopenssl-ruby apache2-prefork-dev libapr1-dev libaprutil1-dev
Download the Ruby source code and compile it
cd ~
mkdir ruby_src
cd ruby_src
tar -zxvf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
sudo make install
Verify Ruby installed correctly
ruby -v
Expected output is "ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]"
Download the RubyGems source code and compile it
cd ~
mkdir rubygems_src
cd rubygems_src
tar -zxvf rubygems-1.8.12.tgz
cd rubygems-1.8.12
sudo ruby setup.rb
Verify RubyGems installed correctly
gem -v
Expected output is "1.8.12"
Install Rails
sudo gem install rails
Verify Rails installed correctly
rails -v
Expected output is "Rails 3.1.3"
Install Phusion Passenger
sudo gem install passenger
sudo passenger-install-apache2-module
Configure Apache by adding these lines to /etc/apache2/apache2.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/apache2/
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.11
PassengerRuby /usr/local/bin/ruby
Configure your rails application by adding these lines to /etc/apache2/apache2.conf, assuming the name of your app is Mytest. Make sure to change the ServerName to the name of the server.
      <VirtualHost *:80>
        DocumentRoot /usr/local/mytest/public
        <Directory /usr/local/mytest/public>
           AllowOverride all
           Options -MultiViews
Restart Apache
sudo /etc/init.d/apache2 restart
Modify the Gemfile to include execjs and therubyracer if needed. Then run "sudo bundle install"
Rails application housekeeping
sudo bundle update
RAILS_ENV=production rake db:create db:schema:load
rake assets:precompile
sudo /etc/init.d/apache2 restart