Topic: Apache and FastCGI problems

Hi, it will be my first post and first big trouble with RoR.
I am using Rails 1.2.0 (as I remember) or 1.2.2 on Windows machine. I got hosting which supports Rails 1.2. I just generating RoR application to test hosting. Hosting is running on Linux. I am going to write steps I used to upload my testing application and later note the problem.

1. I am uploading application folder to server. So it would be easy to access it (Later I would make vhost).
2. In there files: dispatch.fcgi, dispatch.rb I changed ruby path (#!/usr/local/bin/ruby)
3. I went to /public/ directory and found ".htaccess" and changed it to use FastCGI (dispatch.fcgi)
4. chmoded:
dispatch.fcgi - 755
dispatch.rb - 755
/public/ - 755
5. Now I went to /config/ directory and found environment.rb uncommented this line: ENV['RAILS_ENV'] ||= 'production'

Trying to test RoR application, URL:
Pressing "About your application

Last edited by davidlt (2007-03-20 14:25:21)

Re: Apache and FastCGI problems

You're not alone :-)

First, try switching back to cgi from fcgi.  It's slow, but it's helpful to use cgi just to find out what's working/not working in your application.
Then, try the steps outlined here: … t-properly

In particular I suggest looking at the bottom of your log files (either development.log or production.log) for error messages.  They'll give you clues as to what to try.  Feel free to post the log messages here.

Re: Apache and FastCGI problems

Switching from FCGI to CGI. Website works a lot of faster now.
Error from the log, which I got from CPanel (All longs in /log/ directory are empty, I think I didn't set up them, that should be done in vhost configuration maybe)

[2007-03-20 13:09:29]: error: directory is writable by others: (/home/davidlt/public_html/portal/public)
[Tue Mar 20 13:09:29 2007] [error] [client] Premature end of script headers: /home/davidlt/public_html/portal/public/dispatch.cgi

Application error
Rails application failed to start properly"

Hm... How I remember tat FCGI needs some time to take effect, I had forgot that. CGI is better for development.

Now I am going to try that link you provided and then update this post...

UPDATE: That manual didn't work for me. And one more thing, I don't have access to host using SSH.

Hm... Could the problem be with the path to Ruby on the system?.. (Found this commmand: whereis ruby, which should show the path, but I don't such kind of access)

Tried to change path to Ruby in:
dispatch.cgi (Using CGI now)
/usr/bin/env ruby
/usr/local/bin/ruby <- I got this path from server admin, the problem he doesn't know anything about ruby and rails.

Last edited by davidlt (2007-03-21 05:21:42)

Re: Apache and FastCGI problems

Did you also change the permissions for the tmp folder?...should have rw permissions.

Re: Apache and FastCGI problems

Checked and even changed it to 777...
[2007-03-21 13:38:20]: error: file is writable by others: (/home/davidlt/public_html/portal/public/dispatch.cgi)
[2007-03-21 12:08:06]: error: file is writable by others: (/home/davidlt/public_html/portal/public/dispatch.cgi)
[Wed Mar 21 13:38:20 2007] [error] [client] Premature end of script headers: /home/davidlt/public_html/portal/public/dispatch.cgi

Hm... Maybe someone could make test application, the only thing that you would need it Ruby path in server and I already wrote it. I could test that application on server, maybe I have some problems...

Re: Apache and FastCGI problems

I would not set the scripts to mode 777, it seems apache doesn't like that either.

I typically set tmp/sessions and log to mode 1777, then the logs to 666 (in case it ran under a different UID, you can chown it/delete it instead and use 644).

I'm having bad problems with fastcgi too, from what I've learned it seems the dispatch script needs the full path to the ruby binary, not a symlink and not a /usr/bin/env trick.

I think I'm just going to switch to running lighttpd in a virtual machine myself, apache/fastcgi is a real hassle to babysit, load typically hits 15+ after I restart apache, often crashing the machine.

Re: Apache and FastCGI problems

You might also want to consider Apache+Mongrel … nd-mongrel … k-on-track

In hindsight, I should have gone down that route rather than the hassle of setting up Apache + FastCGI

Re: Apache and FastCGI problems

Just as a follow up I did change it over to lighttpd, it rocks.  One reason I preferred it over mongrel is that lighttpd is now in debian stable, so that means more people running a similar config, automatic updates, etc.  In fact I only installed rails 1.2 from experimental (due to a nil caching bug), everything else is straight from stable.