After a fresh
installation of the
Ruby on Rails development environment on my Powerbook and a migration of my previous applications into that environment, I was unable to start any of them. There are two ways of starting up an RoR application. The first and simplest way is to use the
WebRick HTTP server included in your Rails installation. The command for it is as follows:
- Windows: ruby script/server webrick
- Unix/Mac/Linux: script/server webrick
After running the command, you should be able to see your server starting and by directing your browser to [
http://localhost:3000], access your application's main page.
The second way of starting up an RoR application is by not specifying the webrick argument on the command line. It would look like this:
- Windows: ruby script/server
- Unix/Mac/Linux: script/server
What happens in this case is that the script will lookup your LightTPD installation and try to startup the rails application using it. Most of the time, this would work right out of the box. Sometimes however, if you've installed
fastCGI with LightTPD, you might run into the following error:
=> Booting lighttpd (use 'script/server webrick' to force WEBrick)
=> Rails application started on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)
/Users/jeanpaul/webworkspace/ToDo/public/../config/boot.rb:18:in `require': No such file to load -- rubygems (LoadError)
from /Users/jeanpaul/webworkspace/ToDo/public/../config/boot.rb:18
from /Users/jeanpaul/webworkspace/ToDo/public/../config/environment.rb:11:in `require'
from /Users/jeanpaul/webworkspace/ToDo/public/../config/environment.rb:11
from /Users/jeanpaul/webworkspace/ToDo/public/dispatch.fcgi:21:in `require'
from /Users/jeanpaul/webworkspace/ToDo/public/dispatch.fcgi:21
2007-01-20 00:51:56: (mod_fastcgi.c.1048) the fastcgi-backend /Users/jeanpaul/webworkspace/ToDo/public/dispatch.fcgi failed to start:
2007-01-20 00:51:56: (mod_fastcgi.c.1052) child exited with status 1 /Users/jeanpaul/webworkspace/ToDo/public/dispatch.fcgi
2007-01-20 00:51:56: (mod_fastcgi.c.1055) if you try do run PHP as FastCGI backend make sure you use the FastCGI enabled version.
You can find out if it is the right one by executing 'php -v' and it should display '(cgi-fcgi)' in the output, NOT (cgi) NOR (cli)
For more information check http://www.lighttpd.net/documentation/fastcgi.html#preparing-php-as-a-fastcgi-program
2007-01-20 00:51:56: (mod_fastcgi.c.1060) If this is PHP on Gentoo add fastcgi to the USE flags
2007-01-20 00:51:56: (mod_fastcgi.c.1356) [ERROR]: spawning fcgi failed.
2007-01-20 00:51:56: (server.c.834) Configuration of plugins failed. Going down. If you took a chance and directed your browser to [
http://localhost:3000], you might see a [
500 - Internal Server Error] being displayed.
What all these errors suggest is that your rubygems path is wrong or that you did not install rubygems at all. After spending quite sometime struggling with this, I found out that all that needed to be done was to change the path to ruby in your [
dispatch.fcgi] file. In order to get that done, run the following command on your terminal / command prompt:
In my case, the returned result was [
/usr/local/bin/ruby]. It might be slightly different in yours but this does not really matter. Take note of the path to ruby as displayed on your terminal.
The next step is to open the [
dispatch.fcgi] file and change the path to ruby at the beginning of the file to what had been displayed on the terminal. The [
dispatch.fcgi] file usually sits in the [
public] folder of your rails application. When you open the file, you should see something similar to the following line at the beginning of it:
You will need to change that line from whatever was there to the following:
- #!/your/path/to/ruby/as/known/by/your/computer
- In my case, that would be #!/usr/local/bin/ruby
Save the file you just edited and restart your server. If you do not get any further warnings or errors displayed on your terminal after starting up the server, you can safely direct your browser to [
http://localhost:3000] and you should be able to see your application running.
Voila! You just got Rails to run with LightTPD and mod_fcgi. ;-)