Apache
Run the following to install passenger, an apache module that adds support for running rails apps within apache:
sudo gem install passenger sudo passenger-install-apache2-module
Now you have to configure apache to point to the passenger module. Simply copy the following suggested code from the passenger-install-apache2-module
installation to the end of your Apache configuration file, which can be accessed by typing in the command sudo gedit /etc/apache2/apache2.conf
: (if you are using RubyGems 1.1):
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-1.0.3/ext/apache2/mod_passenger.so RailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.3/bin/passenger-spawn-server RailsRuby /usr/bin/ruby1.8
(if you are using RubyGems 1.2):
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3 PassengerRuby /usr/bin/ruby1.8
(if you are using RubyGems 1.3.1):
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6 PassengerRuby /usr/bin/ruby1.8
Now you should point apache to the location of your Ruby app. Create something like this in /etc/apache2/sites-available/ror.myhost.com
<VirtualHost *> ServerName ror.myhost.com DocumentRoot /home/myuser/www/mynewapp/public </VirtualHost>
Alternatively, you could run rails in a specific sub uri of your current host, e.g. localhost. First, make a symbolic link to your rails public folder from with var/www (or wherever you have the root of your apache www folder), e.g.:
ln -s /home/myuser/www/mynewapp/public /var/www/mynewapp
In case of localhost (which is the default host with a fresh ubuntu/apache install) edit default
in /etc/apache2/sites-available
and add:
RailsBaseURI /mynewapp
murb: I had to add RailsEnv development
as well to get around the 'no route found to match "/rails/info/properties" with {:method=>:get}' warning... (can someone elaborate on why?) apparently this is because /info/properties is buggy and no longer supported: http://www.ruby-forum.com/topic/161924 Save, and enable the rewrite module for apache, and register this site... and finally, restart apache.
sudo a2enmod rewrite sudo a2ensite ror.myhost.com sudo /etc/init.d/apache2 restart
Lighttpd
Edit lighttpd.conf, e.g.:
sudo kate /etc/lighttpd/lighttpd.conf
and here starts the tricky part, paste at the end of the file:
server.modules += ( "mod_fastcgi", "mod_rewrite" ) $HTTP["host"] == "localhost" { server.document-root = "/home/santiago/proyectos/beholder/public/" server.dir-listing = "disable" server.error-handler-404 = "/dispatch.fcgi" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 1, "max-procs" => 1, "socket" => "/tmp/ruby-beholder.socket", "bin-path" => "/home/santiago/proyectos/beholder/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development" ) ) ) ) }
now run
sudo /etc/init.d/lighttpd restart
and you're set, go to http://localhost and you should see the rails index... click on the link "About your rails environment" and if you don't see a 404 or 500 error... then you're set (you should see either a rails error, or a rails message or something like that).
Known Problems
just in case you get a message like this:
kmin@metakmin:~/ruby_test$ gem -v 1.2.0 kmin@metakmin:~/ruby_test$ rails -v Rails 2.2.2 kmin@metakmin:~/ruby_test$ gem update --system Updating RubyGems Nothing to update kmin@metakmin:~/ruby_test$ script/server Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update --system` and try again. kmin@metakmin:~/ruby_test$
dont panic, just run:
sudo gem install rubygems-update sudo update_rubygems