Before you start, some important notes: You can replace "myapp" with - well - your app. Also note that this is a little rough. Please leave suggestions or improvements in the comments. Also one very important tip (this took us quite a while to find): First start your app in development mode my setting the Passenger RailsEnv development directive. In production mode, Rails buffers the logger. If will only write stuff to the log file once it has 1000 bytes. Sometimes something fails right away and those 1000 bytes are never reached and hence nothing is ever written to the log file. So do yourself a favor and run in development mode first. So here we go:
- Create httpd.conf:
cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
- Start Apache:
sudo svcadm enable http:apache2
More info here. - Install Ruby Enterprise Edition:
wget http://rubyforge.org/frs/download.php/51100/ruby-enterprise-1.8.6-20090201.tar.gz
- Install GNU Tar (needed for Capistrano, if you use the copy strategy. If not, you don't need it.):
sudo pkg-get install gtar
- If you do use the Capistrano copy strategy, you also need a link from tar to gtar:
cd /home/myapp mkdir capistrano-links cd capistrano-links ln -s /opt/csw/bin/gtar tar
- Unpack Ruby Enterprise Edition:
gtar -xvzf ruby-enterprise-1.8.6-20090201.tar cd ruby-enterprise-1.8.6-20090201/source
- Configure:
./configure --with-openssl-dir=/opt/csw --with-readline-dir=/opt/csw --with-iconv-dir=/opt/csw --prefix=/opt/rubyenterprise --enable-pthread
More info at Dark As Light and at Joyent. - Install REE:
make make install
- Edit your profile:
vi ~/.profile
Then add this:export PATH=/opt/rubyenterprise/bin:/opt/rubyenterprise/lib/gems/bin:$PATH export GEM_HOME=/opt/rubyenterprise/lib/gems export RUBYLIB=/opt/rubyenterprise/lib export RUBYOPT=rubygems
Save and source it:source ~/.profile
- Install RubyGems:
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz gtar -xvzf rubygems-1.3.1.tgz cd rubygems-1.3.1 /opt/rubyenterprise/bin/ruby setup.rb install --prefix=/opt/rubyenterprise/
- Install some gems:
gem install daemons fastthread gem_plugin rake tzinfo rack passenger
- Set some environment variables you that you will need for the passenger installation:
export APXS2=/usr/apache2/bin/apxs export APR_CONFIG=/usr/apache2/bin/apr-config
More info here. - Install Passenger:
passenger-install-apache2-module
- Create a wrapper script for ruby that sets some environment variables:
cd /home/myapp vi ruby_with_env
Then enter this:
#!/bin/sh export PATH=/opt/rubyenterprise/bin:/opt/rubyenterprise/lib/gems/bin:$PATH export GEM_HOME=/opt/rubyenterprise/lib/gems export RUBYLIB=/opt/rubyenterprise/lib export RUBYOPT=rubygems exec "/opt/rubyenterprise/bin/ruby" "$@"
I know that this is a bit hackish and not very elegant. More elegant and working solutions and warmly welcomed. - Put the Passenger stuff into the Apache config:
vi /etc/apache2/httpd.conf
Add these lines:LoadModule passenger_module /opt/rubyenterprise/lib/gems/gems/passenger-2.1.2/ext/apache2/mod_passenger.so PassengerRoot /opt/rubyenterprise/lib/gems/gems/passenger-2.1.2 PassengerRuby /home/myapp/ruby_with_env
- Also add this:
<VirtualHost *:80> ServerName myapp.mycompany.com DocumentRoot /opt/myapp/current/public </VirtualHost>
Also change Group to myapp and User to myapp. - Create a directory for your rails app:
mkdir /opt/myapp
- Restart Apache:
sudo svcadm restart http:apache2
Check that it's online:svcs apache2
- Add this to the bottom of /etc/ssh/sshd_config:
# for capistrano PermitUserEnvironment yes
- Install Rails:
gem install rails
- Change to the shared/config directory:
mkdir /opt/myapp/shared/config
- Copy your database.yml to /opt/myapp/shared/config/database.yml.production and enter your production values. IMPORTANT: remove all other entries, that might use a different database adapter! This prevented Passenger from working for me.
- Deploy:
(I assume that you have capified your project)
On your client machine, in your project directory, run this:
cap staging deploy:setup cap staging deploy:cold
- That's it!
If this was useful for you, please take a minute and recommend me:
Thank you!
Comments
Sylvain Gibier said...
Excellent post ! I've been looking for these steps for a while.
Cheers - Sylvain
Sam Freiberg said...
Nice write up. By the way I recently spent some time getting RMagick compiled against the new version of ImageMagick (from OpenCSW) if you need it. :)
May 01, 2009 11:28 PM