This is not as straightforward as one would hope for, so I put together a quick and dirty guide to get running.
Prereqs: Ruby, Sun Studio Express, and AMP are installed.
- See if Ruby gem compile settings for native code need to be corrected. This works around an OpenSolaris 2008.05 defect.
If /usr/ruby/1.8/lib/ruby/1.8/i386-solaris2.11/rbconfig.rb refers to /opt/SUNWspro, rename the file and replace it with http://blogs.sun.com/prashant/resource/sun_studio/rbconfig.rb. With that change, native code for gems will be successfully compiled with Sun Studio Express.
(In OpenSolaris 2008.11 b95, a workable rbconfig.rb is present which will use gcc to compile native code for gems.) - Build the FastCGI programming library using Sun Studio Express.
$ wget http://fastcgi.com/dist/fcgi.tar.gz $ gtar -xzf fcgi-2.4.0.tar.gz $ cd fcgi-2.4.0 $ CC=cc CXX=CC ./configure --prefix=/usr/local/fcgi-2.4.0 $ make $ pfexec make install
- Install the Ruby fcgi gem.
$ pfexec gem install fcgi -- --with-fcgi-lib=/usr/local/fcgi-2.4.0/lib \ --with-fcgi-include=/usr/local/fcgi-2.4.0/include
- Create a FastCGI application.
Put these two files in $HOME/fastcgi:
- the app itself, myfcgi.rb
require "fcgi" FCGI.each { |request| request.out.print "Content-Type: text/plain\n\nHello from #{__FILE__}" request.finish } -
a wrapper, myfcgi
#!/bin/sh ROOT=`dirname $0` exec ruby -I /var/ruby/1.8/gem_home/gems/fcgi-0.8.7/lib/ $ROOT/myfcgi.rb
Make the wrapper executable:
$ chmod 0755 myfcgi
- the app itself, myfcgi.rb
- Enable FastCGI in Apache
- Add this file to the directory /etc/apache2/2.2/conf.d; call it mod_fcgid.conf. Be sure to substitute the proper directory on the Alias directive.
LoadModule fcgid_module libexec/mod_fcgid.so SharememPath /var/run/fcgid_shm SocketPath /tmp/fcgid_sock/ # !!!Replace /export/home/trawick/fastcgi with the location # where you placed the sample app.!!! Alias /fastcgi /export/home/trawick/fastcgi
<Location /fastcgi> SetHandler fcgid-script Options ExecCGI allow from all </Location>
- Restart Apache to pick up the new config.
$ pfexec svcadm restart apache22
- Add this file to the directory /etc/apache2/2.2/conf.d; call it mod_fcgid.conf. Be sure to substitute the proper directory on the Alias directive.
- Run the app
$ firefox http://127.0.0.1/fastcgi/myfcgi
Hints for one issue or another were gathered from these and other places:
- http://www.hardhathosting.com/community/forums/archive/index.php/t-201.html
- http://blogs.sun.com/prashant/entry/where_s_my_ruby
- http://wiki.rubyonrails.org/rails/pages/Rails+on+CentOS+4.3+with+Apache+and+FastCGI+Simply
Todo:
- Understand why fcgi isn't in the default Ruby search path.
- Try with current 2008.11 development drivers and see if it is simpler.
Any plans for getting Phusion Passenger (http://www.modrails.com/) working with Sun Web Stack? If you want rails on solaris, currently the only decent deployment methods are a mongrel or thin cluster behind an apache server as a load balancer.
Passenger simplifies this quite a bit.
Alternatively, bundling Haproxy (haproxy.1wt.eu) with the sun web stack would be another, equally appreciated addition. You'd still have to setup a thin or mongrel cluster, but it doesn't just round robin the load balancing like apache - it can tell if a mongrel node is busy, and use the next one instead.
Anyway, I greatly anticipate new developments in the sun web stack! Thanks for all your great work.
Posted by Nick Kaltner on October 14, 2008 at 03:59 PM PDT #