Forum: Ruby on Rails I can't get mod_fcgid to work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-09 11:16
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
86ddc542798310ccce177f577d3a30d1?d=identicon&s=25 Matt Jones (Guest)
on 2006-04-09 12:12
(Received via mailing list)
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 Hendrikx <mjhendrikx@yahoo.com> wrote:

> (communication
> Rails mailing list
> Rails@lists.rubyonrails.org
> 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
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-09 12:21
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
`const_missing'
        from dispatch.fcgi:24

Maarten
86ddc542798310ccce177f577d3a30d1?d=identicon&s=25 Matt Jones (Guest)
on 2006-04-09 14:45
(Received via mailing list)
Do you have Ruby fcgi support installed?

gem install fcgi

And this line in your .htaccess:

AddHandler fcgid-script .fcgi

Matt

--- Maarten Hendrikx <mjhendrikx@yahoo.com> 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
> Rails@lists.rubyonrails.org
> 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
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-09 14:56
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
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-04-09 17:40
(Received via mailing list)
Have you installed FastCGI libraries?

www.fastcgi.org

--
-- Tom Mornini
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-09 18:11
Tom Mornini wrote:
> Have you installed FastCGI libraries?
>
> www.fastcgi.org
>
> --
> -- Tom Mornini

I installed mod_fcgid, not mod_fastcgi.
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-04-09 21:31
(Received via mailing list)
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 Mornini
435630373f6ee0fd7d1e0142d1ccb625?d=identicon&s=25 Peter Gibbons (Guest)
on 2006-04-10 05:38
Maarten Hendrikx 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

<IfModule mod_fcgid.c>
  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
</IfModule>

If you have plenty of RAM, then increase DefaultMaxClassProcessCount to
about 2*CPU--assume each instance will eat 20-30MB RAM.
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-10 11:20
> <IfModule mod_fcgid.c>
>   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
> </IfModule>
>

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?
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-10 14:11
(Received via mailing list)
On Mon, Apr 10, 2006 at 11:20:39AM +0200, Maarten Hendrikx wrote:
} > <IfModule mod_fcgid.c>
} >   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
} > </IfModule>
} >
}
} 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
F719c6cb34bd5b691c12b373b7244b4d?d=identicon&s=25 Dorian Mcfarland (tachekent)
on 2006-04-10 17:35
(Received via mailing list)
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
> </IfModule>

--
I do things for love or money
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-11 11:50
> } 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...
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-11 16:15
(Received via mailing list)
On Tue, Apr 11, 2006 at 11:50:48AM +0200, Maarten Hendrikx 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
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-11 22:44
> 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...
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-11 23:06
(Received via mailing list)
On Tue, Apr 11, 2006 at 10:44:11PM +0200, Maarten Hendrikx 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
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-12 11:05
Ok, thanks for all the help. But I'm giving this up. Too bad...
5fa4bbe2cd502510e7702ae1b845f2dd?d=identicon&s=25 Maarten Hendrikx (mrtnhndrkx)
on 2006-04-12 12:53
Maarten Hendrikx 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!
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-12 13:57
(Received via mailing list)
On Wed, Apr 12, 2006 at 12:53:24PM +0200, Maarten Hendrikx wrote:
} Maarten Hendrikx 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
This topic is locked and can not be replied to.