I can't get mod_fcgid to work


#1

Hi,

I just installed mod_fcgid on my apache2 server.
When I try to load my application I get an
“Application error - Rails application failed …” message.

In my Apache2 error-log it says:
Premature end of script headers dispatch.fcgi
mod_fcgid process /data/www/app/dispacth.fcgi exit (communication
error),
terminated by calling exit(), return code 1

Any help with this would be fantastic.

Maarten


#2

This is definitely one of the more annoying parts of
setting up a Rails application.

The first thing I’d suggest is to make sure all your
permissions are correct on the server you’re uploading
to – correct owners, correct groups, log files
writable, scripts executable, /tmp directory free of
old session files belonging to the wrong user. If
that’s all kosher, here’s a way to find out exactly
what’s stopping your dispatcher.

Find your Dispatcher class in your Rails installation.
On my Debian system, it’s in
/usr/lib/ruby/gems/1.8/gems/rails-0.14.4/lib/dispatcher.rb.

Then, find the dispatch method. You’ll find a place
where a block is passed to a function
‘failsafe_response’. Comment out that line and the
corresponding ‘end’ so that the process_with_exception
call is simply executed, not in a block. Save this
change then try running the dispatch.fcgi script
manually. It should spit out a useful error.

To be honest it’s a while since I’ve done this, so I
might have got some details wrong, but I reckon you
get the idea. The trick is to make the dispatcher
spit out a useful error message. Once you can do
that, you’re swimming.

(BTW – you should return the dispatcher to its
original state after you fix the problem.)

Hope that helps.

Matt

— Maarten H. removed_email_address@domain.invalid wrote:

(communication
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


#3

This is the output when I do: ruby dispatch.fcgi

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:112:in
const_missing': uninitialized constant RailsFCGIHandler (NameError) from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:120:inconst_missing’
from dispatch.fcgi:24

Maarten


#4

Do you have Ruby fcgi support installed?

gem install fcgi

And this line in your .htaccess:

AddHandler fcgid-script .fcgi

Matt

— Maarten H. removed_email_address@domain.invalid wrote:

This is the output when I do: ruby dispatch.fcgi

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:112:in

`const_missing’: uninitialized constant
RailsFCGIHandler (NameError)
from

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:120:in

removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


#5

Ok, I tried that and this is the output (can’t be good):

Building native extensions. This could take a while…
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/local/bin/ruby
–with-fcgi-dir
–without-fcgi-dir
–with-fcgi-include
–without-fcgi-include=${fcgi-dir}/include
–with-fcgi-lib
–without-fcgi-lib=${fcgi-dir}/lib
ERROR: While executing gem … (RuntimeError)
ERROR: Failed to build gem native extension.
Gem files will remain installed in
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1 for inspection.
ruby extconf.rb install fcgi\nchecking for fcgiapp.h… no
checking for fastcgi/fcgiapp.h… no

Results logged to
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/ext/gem_make.out


#6

Tom M. wrote:

Have you installed FastCGI libraries?

www.fastcgi.org


– Tom M.

I installed mod_fcgid, not mod_fastcgi.


#7

Have you installed FastCGI libraries?

www.fastcgi.org


– Tom M.


#8

That’s the add on for Apache. You need an add on
for Ruby also. I use Lighttpd, so I’m not 100%
sure how you do it, but I had to installed
the FastCGI libraries and then install the
FastCGI gem, which may require the FastCGI
libraries.


– Tom M.


#9

Maarten H. wrote:

Hi,

I just installed mod_fcgid on my apache2 server.
When I try to load my application I get an
“Application error - Rails application failed …” message.

In my Apache2 error-log it says:
Premature end of script headers dispatch.fcgi
mod_fcgid process /data/www/app/dispacth.fcgi exit (communication
error),
terminated by calling exit(), return code 1

Any help with this would be fantastic.

Maarten

mod_fcgid tips (tested on Apache 2.0.55 and mod_fcgid-1.08 on Debian
3.1)

Make sure you set IPCCommTimeout to at least 45 to allow enough startup
time.
Set DefaultMaxClassProcessCount to 2 unless your benchmarks tell you to
change.
Set IdleTimeout to 3600 or higher since your only have 2 dispatch.fcgi.
Set ProcessLifeTime to a multiple of IdleTimeout.
Set MaxProcessCount > DefaultMaxClassProcessCount so you can use
mod_fcgid for other things than rails.

mod_fcgid religiously kills idle or old processes so keep IdleTimeout
and ProcessLifeTime to high values.

Here is an example ‘starter’ /etc/apache2/mods-enabled/fcgid.conf

AddHandler fcgid-script .fcgi SocketPath /var/lib/apache2/fcgid/sock IdleTimeout 3600 ProcessLifeTime 7200 MaxProcessCount 8 DefaultMaxClassProcessCount 2 IPCConnectTimeout 8 IPCCommTimeout 60 DefaultInitEnv RAILS_ENV production

If you have plenty of RAM, then increase DefaultMaxClassProcessCount to
about 2*CPU–assume each instance will eat 20-30MB RAM.


#10

On Mon, Apr 10, 2006 at 11:20:39AM +0200, Maarten H. wrote:
} >
} > AddHandler fcgid-script .fcgi
} > SocketPath /var/lib/apache2/fcgid/sock
} > IdleTimeout 3600
} > ProcessLifeTime 7200
} > MaxProcessCount 8
} > DefaultMaxClassProcessCount 2
} > IPCConnectTimeout 8
} > IPCCommTimeout 60
} > DefaultInitEnv RAILS_ENV production
} >
} >
}
} Ok, I added this to my httpd.conf and restarted.
} My app now produces a 503 error and I have this in
} my error log:
} [Mon Apr 10 12:21:01 2006] [error] (13)Permission denied: mod_fcgid:
} couldn’t bind unix domain socket /var/lib/apache2/fcgid/sock/3842.3
} [Mon Apr 10 12:21:01 2006] [warn] (13)Permission denied: mod_fcgid:
} spawn process /data/www/http/homepage/dispatch.fcgi error
}
} Ideas?

Does /var/lib/apache2/fcgid/sock exist? Is it
readable-writable-executable
by www-data? The error says “Permission denied” so I’d look for
permission
problems.

–Greg


#11
AddHandler fcgid-script .fcgi SocketPath /var/lib/apache2/fcgid/sock IdleTimeout 3600 ProcessLifeTime 7200 MaxProcessCount 8 DefaultMaxClassProcessCount 2 IPCConnectTimeout 8 IPCCommTimeout 60 DefaultInitEnv RAILS_ENV production

Ok, I added this to my httpd.conf and restarted.
My app now produces a 503 error and I have this in
my error log:
[Mon Apr 10 12:21:01 2006] [error] (13)Permission denied: mod_fcgid:
couldn’t bind unix domain socket /var/lib/apache2/fcgid/sock/3842.3
[Mon Apr 10 12:21:01 2006] [warn] (13)Permission denied: mod_fcgid:
spawn process /data/www/http/homepage/dispatch.fcgi error

Ideas?


#12

Is there any way to incorporate these values into a virtualhost config?

I’m trying to set the rails environment on a per vhost basis on the same
server (i.e dev., www.). Using SetEnv in a directory seems to do
nothing. Obviously I can only have one fcgid.conf.

IPCCommTimeout 60
DefaultInitEnv RAILS_ENV production


I do things for love or money


#13

} My app now produces a 503 error and I have this in
} my error log:
} [Mon Apr 10 12:21:01 2006] [error] (13)Permission denied: mod_fcgid:
} couldn’t bind unix domain socket /var/lib/apache2/fcgid/sock/3842.3
} [Mon Apr 10 12:21:01 2006] [warn] (13)Permission denied: mod_fcgid:
} spawn process /data/www/http/homepage/dispatch.fcgi error
}
} Ideas?

Does /var/lib/apache2/fcgid/sock exist? Is it
readable-writable-executable
by www-data? The error says “Permission denied” so I’d look for
permission
problems.

–Greg

Yes, my web server user is httpd at it can read-write-execute.
I also tried to set it to 777. To no avail…


#14

On Tue, Apr 11, 2006 at 11:50:48AM +0200, Maarten H. wrote:
}
} > } My app now produces a 503 error and I have this in
} > } my error log:
} > } [Mon Apr 10 12:21:01 2006] [error] (13)Permission denied:
mod_fcgid:
} > } couldn’t bind unix domain socket
/var/lib/apache2/fcgid/sock/3842.3
} > } [Mon Apr 10 12:21:01 2006] [warn] (13)Permission denied:
mod_fcgid:
} > } spawn process /data/www/http/homepage/dispatch.fcgi error
} > }
} > } Ideas?
} >
} > Does /var/lib/apache2/fcgid/sock exist? Is it
} > readable-writable-executable
} > by www-data? The error says “Permission denied” so I’d look for
} > permission
} > problems.
} >
} > --Greg
}
} Yes, my web server user is httpd at it can read-write-execute.
} I also tried to set it to 777. To no avail…

Can the user traverse the entire path? That means that the user must
have
at least execute privileges on /var, /var/lib, /var/lib/apache2, and
/var/lib/apache2/fcgid.

–Greg


#15

Can the user traverse the entire path? That means that the user must
have
at least execute privileges on /var, /var/lib, /var/lib/apache2, and
/var/lib/apache2/fcgid.

–Greg

Yes, I checked that, the error in de Apache log states now:

Rails Error: Unable to access log file. Please ensure that
/data/www/http/homepage/…/config/…/log/production.log exists and is
chmod 0666. The log level has been raised to WARN and the output
directed to STDERR until the problem is fixed.
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:112:in
const_missing': uninitialized constant RailsFCGIHandler (NameError) from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:120:inconst_missing’
from /data/www/http/homepage/dispatch.fcgi:24
[Tue Apr 11 23:45:09 2006] [error] [client 192.168.1.1] Premature end of
script headers: dispatch.fcgi
[Tue Apr 11 23:45:13 2006] [notice] mod_fcgid: process
/data/www/http/homepage/dispatch.fcgi(10156) exit(communication error),
terminated by calling exit(), return code: 1

This is pretty frustrating…


#16

Ok, thanks for all the help. But I’m giving this up. Too bad…


#17

On Tue, Apr 11, 2006 at 10:44:11PM +0200, Maarten H. wrote:
}
} > Can the user traverse the entire path? That means that the user must
} > have
} > at least execute privileges on /var, /var/lib, /var/lib/apache2, and
} > /var/lib/apache2/fcgid.
} >
} > --Greg
}
} Yes, I checked that, the error in de Apache log states now:
}
} Rails Error: Unable to access log file. Please ensure that
} /data/www/http/homepage/…/config/…/log/production.log exists and is
} chmod 0666. The log level has been raised to WARN and the output
} directed to STDERR until the problem is fixed.
}
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:112:in
} const_missing': uninitialized constant RailsFCGIHandler (NameError) } from } /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:120:in }const_missing’
} from /data/www/http/homepage/dispatch.fcgi:24
} [Tue Apr 11 23:45:09 2006] [error] [client 192.168.1.1] Premature end
of
} script headers: dispatch.fcgi
} [Tue Apr 11 23:45:13 2006] [notice] mod_fcgid: process
} /data/www/http/homepage/dispatch.fcgi(10156) exit(communication
error),
} terminated by calling exit(), return code: 1
}
} This is pretty frustrating…

I had a similar problem. I needed GEM_HOME to be set, and it was in my
shell but not in my environment under Apache2. It looks like you can get
to
your gems, though. Is there some other library directory it may not be
finding, or may not have permissions to read?

–Greg


#18

Maarten H. wrote:

Ok, thanks for all the help. But I’m giving this up. Too bad…

Hey, just as I was about to give up: I got it.
I had to install FastCGI and ran gem install fcgi without any problems.
Now the app works with mod_fcgid!


#19

On Wed, Apr 12, 2006 at 12:53:24PM +0200, Maarten H. wrote:
} Maarten H. wrote:
} > Ok, thanks for all the help. But I’m giving this up. Too bad…
}
} Hey, just as I was about to give up: I got it.
} I had to install FastCGI and ran gem install fcgi without any
problems.
} Now the app works with mod_fcgid!

Interesting. I wound up installing the libfcgi-ruby1.8 Debian package,
which apparently contains the same thing.

–Greg