# FastCGI cannot start; Rails doesn't work

**URL:** <https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064>\
**Category:** Rails\
**Created:** [January 10, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064 "2006-01-10T17:05:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 10, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/1 "2006-01-10T17:05:23Z")

</div>

I have a problem deploying FastCGI for use with RoR.

OS: FreeBSD 5.4  
Apache: 2.0.55  
FastCGI: 2.4.2

###### 

I compiled a new mod\_fastcgi.so and copied it to  
/usr/lib/apache/mod\_fastcgi.so

###### 

My httpd.conf looks like this:  
LoadModule fastcgi\_module /usr/lib/apache/mod\_fastcgi.so

 AddHandler fastcgi-script .fcgi
###### 

The testscript i want to execute is the following:

#!/usr/local/bin/ruby  
require ‘cgi’  
require ‘rubygems’  
require\_gem ‘fcgi’

FCGI.each\_cgi do |cgi|  
content = ‘’  
env = []  
cgi.env\_table.each do |k,v|  
env \<\< [k,v]  
end  
env.sort!  
env.each do |k,v|  
content \<\< %Q(#{k} =\> #{v}  
\n)  
end  
cgi.out{content}  
end

#######

The errors i get in apache’s error\_log are:

[Tue Jan 10 16:55:14 2006] [notice] Apache/2.0.55 (Unix)  
mod\_perl/1.99\_17-dev Perl/v5.8.7 PHP/4.4.0 FrontPage/5.0.2.2635  
mod\_fastcgi/2.4.2 mod\_ssl/2.0.55 OpenSSL/0.9.7e configured – resuming  
normal operations  
[Tue Jan 10 16:55:32 2006] [warn] FastCGI: (dynamic) server  
“/home/martijn/domains/martijnvanleeuwen.nl/public\_html/sponsors/public/test.fcgi”  
started (pid 18781)  
FastCGI: can’t start server  
“/home/martijn/domains/martijnvanleeuwen.nl/public\_html/sponsors/public/test.fcgi”  
(pid 18781), execle() failed: No such file or directory  
[Tue Jan 10 16:55:32 2006] [warn] FastCGI: (dynamic) server  
“/home/martijn/domains/martijnvanleeuwen.nl/public\_html/sponsors/public/test.fcgi”  
(pid 18781) terminated by calling exit with status ‘255’

###### 

What did i find out?  
There are only a few examples on the internet with this problem. They  
all say that the first line in the script ‘#!/usr/local/bin/ruby’ points  
to the wrong location. My ruby is in the correct place. Does anyone have  
any idea for this problem?

Thanx in advance,

Martijn

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 10, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/2 "2006-01-10T17:23:31Z")

</div>

On Tue, 2006-01-10 at 17:03 +0100, Martijn van Leeuwen wrote:

> ```
> cgi.env_table.each do |k,v|
> 
> ```
> 
> “/home/martijn/domains/martijnvanleeuwen.nl/public\_html/sponsors/public/test.fcgi”  
> to the wrong location. My ruby is in the correct place. Does anyone have  
> any idea for this problem?

You can always test the script separate of the apache setup by running  
the script at the command line:

cd  
/home/martijn/domains/martijnvanleeuwen.nl/public\_html/sponsors/public/  
./test.fcgi

## Is the ruby fcgi gem installed properly?

-Matthew B.  
removed\_email\_address@domain.invalid :: 607 227 0871  
Resume and Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 10, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/3 "2006-01-10T18:45:05Z")

</div>

Matthew B. schreef:

> > FCGI.each\_cgi do |cgi| end "/home/martijn/domains/martijnvanleeuwen.nl/public\_html/sponsors/public/test.fcgi" What did i find out?
> 
> cd /home/martijn/domains/martijnvanleeuwen.nl/public\_html/sponsors/public/  
> ./test.fcgi
> 
> Is the ruby fcgi gem installed properly?

I used “gem install fcgi”

And it worked like it should, so i don’t think there were any problems  
there. If i try to run an empty script file like empty.fcgi i get the  
same error. So i would think the problem is with fastcgi and maybe  
rights. But i can’t find out where and how. I did the FreeBSD ports  
version and i compilled all stuff myself. But still have problems.

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 10, 2006, 7:27pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/4 "2006-01-10T19:27:25Z")

</div>

I had issues on my setup due to file permissions when I received the ‘No  
such file or directory’ error. I was root when I worked on one of the  
files  
and had to change the ownership.

Worth a shot.

~ Ben

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 10, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/5 "2006-01-10T20:03:50Z")

</div>

It would be ownership of the script files. Does apache run under the  
apache user? (assuming so). Check the other documents in the www  
directory and see what their premission are and compare them to yours.

Its a starting point at least.  
-Nick

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 11, 2006, 2:52pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/6 "2006-01-11T14:52:30Z")

</div>

Nick S. wrote:

> It would be ownership of the script files. Does apache run under the  
> apache user? (assuming so). Check the other documents in the www  
> directory and see what their premission are and compare them to yours.
> 
> Its a starting point at least.  
> -Nick

Ik checked all the ownerships, they are correct. All are the local user,  
none is root.

cgi works, webrick works, but fcgi doesn’t work. I checked fastcgi out  
on a perl script, but i give the same error. So i would think fastcgi  
doesn’t work correctly. I also installed the FreeBSD Ports fcgid module.  
(alternate for fastcgi). It doesn’t work either, i get an communication  
error in my error\_log.

I installed the whole bunch on my Ubuntu Desktop, and it worked almost  
straight away.

I surprises me that i can’t find anything on the web about this problem.

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 10, 2006, 7:33pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/7 "2006-01-10T19:33:26Z")

</div>

Ben R. schreef:

> I had issues on my setup due to file permissions when I received the  
> ‘No such file or directory’ error. I was root when I worked on one of  
> the files and had to change the ownership.
> 
> Worth a shot.
> 
> ~ Ben

You mean ownership of scriptfiles or ownership of ruby? i did it as root  
too. So this could be something.

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 11, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/8 "2006-01-11T15:54:40Z")

</div>

Thats kinda strange that its not running on \*BSD. Never used the \*BSDs  
but figured it would be similar enough to the \*nixs that it wouldn’t  
have any issues. Odd. But at least you got it working in Ubuntu, so  
you know your are doing the right steps…

Sorry I can’t be of any more help =\

-Nick

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 11, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/9 "2006-01-11T14:18:37Z")

</div>

Nick S. wrote:

> It would be ownership of the script files. Does apache run under the  
> apache user? (assuming so). Check the other documents in the www  
> directory and see what their premission are and compare them to yours.
> 
> Its a starting point at least.  
> -Nick

Ik checked all the ownerships, they are correct. All are the local user,  
none is root.

cgi works, webrick works, but fcgi doesn’t work. I checked fastcgi out  
on a perl script, but i give the same error. So i would think fastcgi  
doesn’t work correctly. I also installed the FreeBSD Ports fcgid module.  
(alternate for fastcgi). It doesn’t work either, i get an communication  
error in my error\_log.

I surprises me that i can’t find anything on the web about this problem.

---

<div class="post-metadata">

**Author:** ![Martijn\_van\_Leeuwen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Martijn\_van\_Leeuwen](https://www.ruby-forum.com/u/Martijn_van_Leeuwen)\
**Post date:** [January 11, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/fastcgi-cannot-start-rails-doesnt-work/52064/10 "2006-01-11T18:14:44Z")

</div>

Martijn van Leeuwen wrote:

> Nick S. wrote:
> 
> > It would be ownership of the script files. Does apache run under the  
> > apache user? (assuming so). Check the other documents in the www  
> > directory and see what their premission are and compare them to yours.
> > 
> > Its a starting point at least.  
> > -Nick
> 
> Ik checked all the ownerships, they are correct. All are the local user,  
> none is root.
> 
> cgi works, webrick works, but fcgi doesn’t work. I checked fastcgi out  
> on a perl script, but i give the same error. So i would think fastcgi  
> doesn’t work correctly. I also installed the FreeBSD Ports fcgid module.  
> (alternate for fastcgi). It doesn’t work either, i get an communication  
> error in my error\_log.
> 
> I installed the whole bunch on my Ubuntu Desktop, and it worked almost  
> straight away.
> 
> I surprises me that i can’t find anything on the web about this problem.

I had this problem under dragonflybsd-1.4 and freebsd-4.11 for that  
matter. It came down to file ownership.

If you’re running your RoR app under web root say  
/usr/local/www/data/RoR\_project fcgi is running as the same user as the  
apache process. I had apache running as uid = www, gid = www. Once I  
did a chown -R www:www on the RoR project it worked just fine.

If you are trying to run a application owned by you from your  
public\_html/rails\_project directory you need to have apache compiled  
with suexec support.

If you didn’t compile apache WITH suexec and you are trying to run a RoR  
app which is owned by your uid=my\_uid it won’t work. If you recompile  
apache with suexec(flag in apache port), apache/fcgi will then run a  
application owned by you.

Regards,

Eric
