Passenger for Local Development of Multiple Applications on Ubuntu

Starting with the Railscasts episode on passenger I tried to get passenger working for development, since it removes the burden of always starting an extra console for the server and reveals errors that happen in passenger and not in mongel alone.

Apache should use the same group/user you use, otherwise you may get an 302 not allowed error, this can be changed in /etc/apach2/apache2.conf (User / Group).

httpd.conf

#/ets/apacha2/httpd.conf
# /apps is the folder where your projects lie
# I name them all *.lc so i can easily distinguish them from a live application
# if you use subdomains add the *. before the servername (example 1)
<Directory "/apps">
  Order allow,deny
  Allow from all
</Directory>

<Directory "/apps">
  Options FollowSymLinks
  AllowOverride None
</Directory>

<VirtualHost *:80>
  ServerAlias *.dw.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/someproject/public
</VirtualHost>

<VirtualHost *:80>
  ServerAlias rs.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/anotherproject/public
</VirtualHost>

hosts file

#/ets/hosts
127.0.0.1       de.dw.lc en.dw.lc fr.dw.lc
127.0.0.1       rs.lc
127.0.0.1       localhost
...

restart apache

sudo /etc/init.d/apache2 restart

Hope it works for you 😉

Upgrading Ruby from 1.8.6 to 1.8.7 from Source

UPDATE: Just use RVM or install ruby-enterprise-edition, thats far easier …

Just writing this because it took a lot of time to find a working tutorial
Ubuntu Hardy(8.04) has 1.8.6 installed, and Ibex(8.10) already comes with 1.8.7.

sudo apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
tar zxvf ruby-1.8.7-*
cd ruby-1.8.7-*
./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr
make
sudo make install

Hope it helps but so far did not work out for me, when using /usr/bin/local/ruby xxx.rb rubygems are not found, and when installed using –prefix=/usr , openssl is broken, since it is the 1.8.6 version and not even manually installing ruby-1.8.7 openssl seemed to work…

The Simpelest Mongrel Server (Without Rails)

I tried to make my own small server and mongrel came in handy!
Some things i covered:

  • making the server stop on ctr+c
  • ignoring favicon requests
  • using the local ip (192.168.X.X) or localhost
  • parsing the request parameters (?aaa=bbb&…) to a hash

The rest is up to you!

Stick your code into process, then run ‘ruby server.rb’ and your done 🙂

#server.rb
require 'mongrel'
require 'yaml'

module SimpleServer
  class SimpleHandler < Mongrel::HttpHandler
    def process(request, response)
      return if request.params['REQUEST_URI']=='/favicon.ico'

      params = extract_params request
      puts "Called with:"
      puts params.to_yaml

      response.start(200) do |head,out|
        head["Content-Type"] = "text/plain"
        out.write("HELLO WORLD!")
      end
    end

    def extract_params request
      params = request.params['QUERY_STRING']
      return {} if !params

      arr = params.split('&')

      hash = {}
      arr.each do |value|
        break if !value
        temp = value.split('=')
        hash[temp[0]]= temp[1]
      end 

      hash
    end
  end

  #SERVER
  def self.start
    require 'socket'
    #or use 'localhost' if u do not want to be callable from outside
    host = IPSocket.getaddress(Socket.gethostname)
    config = Mongrel::Configurator.new :host => host, :port => 3000 do
      listener {uri "/", :handler => SimpleHandler.new}
      trap("INT") { stop }
      run
    end

    #show what we are running
    puts "Running at"
    puts config.defaults.to_yaml
    config.join
  end
end

SimpleServer::start