Passenger and Ruby Enterprise Edition on Solaris 10

Posted on 23 March 2009 by Johannes Fahrenkrug. Tags: Tutorials Ruby rails Solaris
I recently had the pleasure of setting up REE and Passenger on Solaris 10. I set the server up using the ibm_db gem for the IBM DB/2 database. I'm not covering this part in this tutorial and I also haven't replaced it with instructions for MySQL. I'm sure you'll figure out how to set up MySQL on Solaris.
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:
  1. Create httpd.conf:
    cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
  2. Start Apache:
    sudo svcadm enable http:apache2
    More info here.
  3. Install Ruby Enterprise Edition:
    wget http://rubyforge.org/frs/download.php/51100/ruby-enterprise-1.8.6-20090201.tar.gz
  4. Install GNU Tar (needed for Capistrano, if you use the copy strategy. If not, you don't need it.):
    sudo pkg-get install gtar
  5. 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
  6. Unpack Ruby Enterprise Edition:
    gtar -xvzf ruby-enterprise-1.8.6-20090201.tar
    cd ruby-enterprise-1.8.6-20090201/source
  7. 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.
  8. Install REE:
    make
    make install
  9. 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
  10. 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/
  11. Install some gems:
    gem install daemons fastthread gem_plugin rake tzinfo rack passenger
  12. 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.
  13. Install Passenger:
    passenger-install-apache2-module
  14. 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.
  15. 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
  16. Also add this:
    <VirtualHost *:80>
       ServerName myapp.mycompany.com
       DocumentRoot /opt/myapp/current/public
    </VirtualHost>
    Also change Group to myapp and User to myapp.
  17. Create a directory for your rails app:
    mkdir /opt/myapp
  18. Restart Apache:
    sudo svcadm restart http:apache2
    Check that it's online:
    svcs apache2
  19. Add this to the bottom of /etc/ssh/sshd_config:
    # for capistrano
    PermitUserEnvironment yes
  20. Install Rails:
    gem install rails
  21. Change to the shared/config directory:
    mkdir /opt/myapp/shared/config
  22. 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.
  23. 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
  24. That's it!

If this was useful for you, please take a minute and recommend me:
Recommend Me
Thank you!



Comments

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

Sylvain Gibier said...

Excellent post ! I've been looking for these steps for a while.

Cheers - Sylvain

April 14, 2009 01:51 PM

Comments

Please keep it clean, everybody. Comments with profanity will be deleted.

blog comments powered by Disqus