3

It's been a few days that I'm trying to set up fastcgi with apache on a Kubuntu server. Despite searching everywhere, I cannot make it to work. If I try to run the site with the cgi application, apache hangs and after the timeout returns a 500 error.

Here is what I did:

  • I made sure that mod_fastcgi is installed and enabled:

    # pwd
    /etc/apache2/mods-enabled
    # ls -l f*
    lrwxrwxrwx 1 root root 30 2010-07-22 10:01 fastcgi.conf -> ../mods-available/fastcgi.conf
    lrwxrwxrwx 1 root root 30 2010-07-22 10:01 fastcgi.load -> ../mods-available/fastcgi.load
    
  • As far as I am aware, fastcgi.conf is properly configured:

    <IfModule mod_fastcgi.c>
      AddHandler fastcgi-script .fcgi
      #FastCgiWrapper /usr/lib/apache2/suexec
       FastCgiIpcDir /var/lib/apache2/fastcgi
    </IfModule>
    
  • I am using this very simple sample script to test the set up:

    #include <iostream>
    using namespace std;
    int main()
    {
            cout<<"Content-type: text/plain"<<endl<<endl;
            cout<<"Hello World!"<<endl;
             return 0;
    }
    
  • I compiled it. It works fine from the command line.
  • I placed it within a folder visible from the web server: http://127.0.0.1/fcgitest/run.fcgi
  • At first I get: "Forbidden. You don't have permission to access /fcgitest/run.fcgi on this server.".
  • I add a .htaccess file in the folder:

    Options +ExecCGI -Indexes
    
  • And now, when I try to access the script address from my web browser, I get the symptom I described at the beggining: the browser first hangs, and after the timeout, I get a 500 Internal Server Error.
  • The apache error.log say:

    Content-type: text/plain
    Hello World!
    [Sat Aug 28 09:08:23 2010] [warn] FastCGI: (dynamic) server 
    "/var/www/fcgitest/run.fcgi" (pid 27758) terminated by calling exit with status '0'
    

It seems the output is written to the error logs!! Is there a missing socket configuration, somewhere??

augustin
  • 385
  • 2
  • 6
  • 14

2 Answers2

2

Your sample script is wrong. It needs to explicitly support FastCGI e. g. through fastcgi++ or the official FastCGI SDK.

But that's more of a question for StackOverflow.

joschi
  • 20,747
  • 3
  • 46
  • 50
  • The library would be for more complex scripts. My understanding is that the script above (with link to the tutorial) is good enough for testing. http://www.cs.tut.fi/~jkorpela/forms/cgic.html is another site with a tutorial. It is hosting an equally simple script that is running here: http://www.cs.tut.fi/cgi-bin/run/~jkorpela/hellow.cgi . I still don't understand why they don't work in my case. – augustin Aug 28 '10 at 10:00
  • Again: CGI != FastCGI. Your script has to explicitly support the FastCGI protocol. You can't just use an arbitrary CGI script like you did. – joschi Aug 28 '10 at 10:14
  • Oh! I see. I've asked at stackoverflow, as you suggested, but I'll see if I can come up with something myself. Thanks for your help. – augustin Aug 28 '10 at 10:20
  • I'll see if I can get one of those working: http://www.fastcgi.com/devkit/examples/ – augustin Aug 28 '10 at 10:21
1

Yep, as noted by joschi, CGI != FastCGI . A CGI script would fail in this context.

http://127.0.0.1/doc/libapache2-mod-fastcgi/mod_fastcgi.html
http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html

FastCGI Specification Compliance

The FastCGI specification is not implemented in its entirety and I've deviated a bit as well resulting in some Apache specific features.

The file descriptors for stdout and stderr are left open. This is prohibited by the specification. I can't see any reason to require that they be closed, and leaving them open prevents FastCGI applications which were not completely ported to FastCGI from failing miserably. This does not mean the applications shouldn't be fixed such that this doesn't occur, but is invaluable when using a 3rd party library (without source code) which expects to be able to write to stderr. Anything written to stdout or stderr in this manner will be directed to the main server log.

augustin
  • 385
  • 2
  • 6
  • 14