logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Third-party Modules View previous topic :: View next topic
Reply to topic   Topic: mod_fcgid doesn't want to work (500) Page 1, 2  Next
Author
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Mon 23 Jul '07 13:19    Post subject: mod_fcgid doesn't want to work (500) Reply with quote

Hey guys,
I wanted to use FastCGI on my Apache 2.2.4 (Windows) with my applications so I downloaded the mod_fcgid off this site and copied it into the "modules" directory.
I've been struggling for 3 days now to get it to work but I just can't figure it out Sad I added this to my httpd.conf:

LoadModule fcgid_module modules/mod_fcgid.so

And to the .htaccess in my homedir:

AddHandler fcgid-script .fcgi

So now when I try to call a fcgi (or just a CGI program renamed to .fcgi) the server spits out a 500 error:

The server encountered an internal error and was unable to complete your request.

Error message:
Premature end of script headers: test.fcgi


I checked the error.log:
Quote:
[Mon Jul 23 13:57:03 2007] [warn] (OS 109)The pipe has been ended. : mod_fcgid: get overlap result error
[Mon Jul 23 13:57:03 2007] [error] [client 127.0.0.1] Premature end of script headers: test.fcgi


The programs work 100% (even in cmd). Additionally I copied the apache cgi demo to my dir and named it printenv.fcgi (for testing purposes):

Code:
print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
   $val = $ENV{$var};
   $val =~ s|\n|\\n|g;
   $val =~ s|"|\\"|g;
   print "${var}=\"${val}\"\n";
}


But the same keeps happening Sad

I absolutely have no clue whatsoever why this is happening.

Btw: The libfcgi.dll is of course in my homedir too Smile
Oh, and I'm using Xampp...

I'd appreciate any suggestions Sad
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7301
Location: Germany, Next to Hamburg

PostPosted: Mon 23 Jul '07 13:35    Post subject: Reply with quote

I miss there two things.

a) the handler / wrapper e.g. FCGIWrapper "C:/some.exe" .fcgi
b) Options Indexes FollowSymLinks ExecCGI
Back to top
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Mon 23 Jul '07 14:05    Post subject: Reply with quote

Hello,
danke for the fast reply Smile

Are you sure I need a FCGIWrapper? Isn't it for PHP? Because all my *.fcgi files are binary and just output their content to the console.

Anyway I tried it and your suggestion b) but with no luck, still the same error Sad

Though If I remove all other configurations on that directory and just leave it to:

SetHandler fcgid-script
Options Indexes FollowSymLinks ExecCGI
allow from all


Windows first tells me
index.fcgi - Application Error: The application failed to initialize properly (0xc0150004). Click on OK to terminate the application.
And only then shows the usual error. It's weird cause all DLLs and stuff are in the same directory as my index.fcgi and when executing that program under Windows console it outputs everything just right without any errors...
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Mon 23 Jul '07 19:26    Post subject: Reply with quote

A FastCGI program is different from a CGI program.

For example, a FastCGI program written in "C" using the FastCGI Developer's Kit usually has a loop like this:
Code:
while (FCGI_Accept() >= 0) {
    ... handle request...
}

An ordinary CGI program handles a single request and exits.

Trying to run a CGI program as FastCGI will give the symptoms that you describe.

-tom-
Back to top
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Sun 29 Jul '07 17:10    Post subject: Reply with quote

Yeah, I know and that's actually how my program looks like.

Okay, I think I overseeing something here, let me describe to you guys what I did step by step.

1.
I downloaded the FastCGI Development Kit from www.fastcgi.com

2.
I extracted its contents into my CGI program directory into the "fcgi" directory (I mean the CGI program I'm trying to "convert" to FastCGI).

3.
I browsed to /fcgi/libfcgi/ in the CMD/Console and did a "nmake". In the /fcgi/libfcgi/Release/ was now a libfcgi.dll and libfcgi.lib and bunch of other stuff.

4.
I wrote a test program:
Code:
#include <iostream>
#include "fcgi/fcgi_config.h"
#include "fcgi/include/fcgi_stdio.h"

int main(int argc, char *argv[])
{
    while(FCGI_Accept() >= 0)
    {
        std::cout << "Content-type: text/html\n\nHello World!";
    }

    return 0;
}

And added the libfcgi.lib to the Linker and compiled my program with no errors.

5.
I copied my compiled program (index.fcgi) and the libfcgi.dll to the httpd-directory.

6.
I copied the "mod_fcgid.so" to the modules directory and added the following to my httpd.config:
LoadModule fcgid_module modules/mod_fcgid.so
And to the .htaccess in my httpd-direcotry I added:
AddHandler fcgid-script .fcgi

7.
I start apache and open IE/FF and type "http://localhost/index.fcgi". All I get is the default apache 500 error page.
But when I open the CMD/Console and browse to my httpd directory and execute the index.fcgi, it prints the following to the CMD/Console/Output:
Quote:
Content-type: text/html

Hello World!

So that would actually mean that my compiled program has no errors and the libfcgi.dll was also found. Otherwise there would've been an error in the OS while executing the index.fcgi, right?


I bet I'm doing something wrong, aren't I?
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Mon 30 Jul '07 3:05    Post subject: fcgi modules Reply with quote

A couple of things:
    index.fcgi goes in your web directory (i.e. in htdocs), not in the Apache directory.
    libfcgi.dll still goes somewhere in the PATH that you set with DefaultInitEnv PATH "..." for fcgid.
    When you run index.fcgi by hand, libfcgi.dll must be in your PATH (or in the same directory as index.fcgi)

    Don't use the C++ iostream cout and cin objects in a fcgi program - even if it is a C++ program.
    Use a regular printf instead. The fcgi_stdio.h header takes care of redefining printf (and the other functions in stdio) to work with fcgi.
    There is nothing similar for iostream.

    By convention, you use \r\n for line endings with HTTP - although your program will still work OK with Apache using just \n.
Try this:
Code:
#include "fcgi/include/fcgi_stdio.h"
int main(int argc, char *argv[])
{   while(FCGI_Accept() >= 0)
    {   printf("Content-type: text/html\r\n\r\nHello World!");
    }
    return 0;
}


-tom-
Back to top
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Mon 30 Jul '07 11:50    Post subject: Reply with quote

Hey,
Thanks, I tried the \r\n and the printf() solution but nothing changed Sad
Of course I meant that I've put the files into the htdocs directory (and not httpd) Smile
That's so weird, I don't get it Sad Still the same 500 error. I changed the LogLebel to debug and here's what it says:

Quote:
[Mon Jul 30 12:41:16 2007] [info] mod_fcgid: server D:/htdocs/fcgi/index.fcgi(1188) started
[Mon Jul 30 12:41:16 2007] [warn] (OS 109)The pipe has been ended. : mod_fcgid: get overlap result error
[Mon Jul 30 12:41:16 2007] [error] [client 127.0.0.1] Premature end of script headers: index.fcgi


There are only 3 files in my D:/htdocs/fcgi/ directory:

- my new index.fcgi
- libfcgi.dll
- .htaccess

.htaccess:
Code:
AddHandler fcgid-script .fcgi
Options Indexes FollowSymLinks ExecCGI

also tried:
Code:
AddHandler fcgid-script .fcgi


But no luck Sad And again, starting index.fcgi from the console outputs the stuff just right without any runtime errors :'-(

Maybe someone can send me for testing purposes a index.fcgi and the libfcgi.dll, that's 100% working on his machine with fastcgi? Just a simple Hello World thingy so I can somehow narrow down the source of the error...
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Mon 30 Jul '07 13:20    Post subject: Reply with quote

What DefaultInitEnv directives do you have in httpd.conf? The PATH environment variable is especially important to get correct.

You should have something like this:
Code:
    DefaultInitEnv PATH "C:/WINDOWS/System32;C:/WINDOWS;C:/Apache2/bin"
    DefaultInitEnv SystemRoot "C:/WINDOWS"
    DefaultInitEnv SystemDrive "C:"
    DefaultInitEnv windir "C:/WINDOWS"
    DefaultInitEnv TEMP "C:/TEMP"
    DefaultInitEnv TMP "C:/TEMP"

-tom-
Back to top
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Mon 30 Jul '07 15:49    Post subject: Reply with quote

Apparently I didn't have any DefaultInitEnv set, so I appended them to the httpd.confg:
Code:
DefaultInitEnv PATH "C:/Windows/system32;C:/Windows;D:/Xampp/apache/bin;D:/htdocs/fcgi"
DefaultInitEnv SystemRoot "C:/Windows"
DefaultInitEnv SystemDrive "C:"
DefaultInitEnv windir "C:/Windows"
DefaultInitEnv TEMP "D:/Xampp/tmp"
DefaultInitEnv TMP "D:/Xampp/tmp"


But nothing has changed Sad All error messages are still the same...
Has anyone a testable index.fcgi (hello world) and libfcgi.dll so I can test it on my system?
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Mon 30 Jul '07 20:41    Post subject: Reply with quote

re "Maybe someone can send me for testing purposes a index.fcgi and the libfcgi.dll, that's 100% working on his machine with fastcgi? "

Sure - the example from my previous post is working fine on my system.

Send it to you how?

-tom-
Back to top
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Tue 31 Jul '07 9:24    Post subject: Reply with quote

Well, maybe I have some weird compiler settings or something Smile
It would be really nice of you if you could upload the libfcgi.dll and your small test example to http://www.sharebigfile.com/ (the "Upload" button is at the bottom right, lol) and post the links here Smile
Thanks!
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Tue 31 Jul '07 14:07    Post subject: Reply with quote

http://www.sharebigfile.com/file/200066/example-zip.html

-tom-
Back to top
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Wed 01 Aug '07 12:52    Post subject: Reply with quote

Weird... everytime a try to run it in my webbrowser it tells me the same thing as in my other programs. a message box pops up and says:

Quote:
Runtime Error!

Program: D:\htdocs\index.fcgi

R6034
An application has made an attemtpt to load the C runtime library incorrectly.
Please contact the application's support team for more information.


I don't get it Sad
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Wed 01 Aug '07 15:13    Post subject: Reply with quote

The R6034 error is useful to know. It indicates that the problem is related to manifest files.

I'm guessing that you are building your app with VS8 (i.e. Visual Studio 2005 C++). The Express edition maybe?

Try this version: http://www.sharebigfile.com/file/200435/example-zip.html

This version has VS8 manifests embedded in both libfcgi.dll and in index.fcgi

-tom-
Back to top
suarsg



Joined: 23 Jul 2007
Posts: 8

PostPosted: Wed 01 Aug '07 20:00    Post subject: Reply with quote

lol yeah, that's exactly what i'm using (express edition) and that was kinda the reason why i wanted a compiled example Very Happy
well, it still shows the exact same error... it's so weird that i'm starting to believe it has something to do with the apache "modified" version in xampp (i'm using xampp) Sad
by the way, since all the windows message boxes started to appear, a new error is now added to the log while executing:

Quote:
[Wed Aug 01 20:52:01 2007] [info] mod_fcgid: server D:/htdocs/index.fcgi(3116) started
[Wed Aug 01 20:52:02 2007] [warn] (OS 109)The pipe has been ended. : mod_fcgid: get overlap result error
[Wed Aug 01 20:52:02 2007] [error] [client 127.0.0.1] Premature end of script headers: index.fcgi
[Wed Aug 01 20:52:05 2007] [info] mod_fcgid: process D:/htdocs/index.fcgi(3116) exit(communication error), return code -1073741502


when opening http://localhost/index.fcgi the first the errors are written to the log, then the message box pops up, then i click "ok" and the server shows the 500 error page and writes the communication error to the log...
i also tried to use the "original" mod_fastcgi but i couldn't find anywhere a binary for apache 2.2 (hasn't been really ported yet, but there's a patch for the source code to make it work with apache 2.2 but i'd have to compile it myself and i don't have the apache source and i'm currently out of the country and the internet connection is horrible here...)

it all sounds like apache tries to start the process in a weird kinda way, i mean without the needed environment variables/paths Sad
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Thu 02 Aug '07 2:53    Post subject: Reply with quote

Possibly the problem is the VS8 runtime libraries. If you had downloaded Apache from Apache Lounge, one of the installation steps would have been to install the VS8-SP1 runtime libraries. These libraries are available from Microsoft here.

I don't think the XAMPP version of Apache uses or supplies the VS8 runtime libraries.

If you have VS8 Express Edition and you have installed Service Pack 1 (SP1) - then you should have the correct runtime libraries already installed on your system.

If you have not installed SP1, then you have an older version of the runtime libraries, and that may be the problem.
It is safe to install the SP1 libraries even if you do not have SP1. Both the original libraries and SP1 libraries can be on your system without interference.

The binaries that I provided require the SP1 runtime libraries.

-tom-
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7301
Location: Germany, Next to Hamburg

PostPosted: Thu 02 Aug '07 9:20    Post subject: Reply with quote

I tested the second download on my XP where VS8-SP 1 is installed. The fcgi ran on the apache from apachelounge (VS8) and on the one from ASF (VS6).
Back to top
tomw



Joined: 10 Sep 2007
Posts: 4

PostPosted: Mon 10 Sep '07 21:38    Post subject: Reply with quote

I am just starting a new project with fcgi and getting very similar results to suarsg.

I am using a trial version of Visual Studio 8 (Professional edition) for development. I have also downloaded and installed the VC runtime service pack 1.

The fastcgi app was compiled with the library from fastcgi.com

I am running the app as dynamic fastcgi.

The log shows:
[Mon Sep 10 15:17:49 2007] [warn] (OS 109)The pipe has been ended. : mod_fcgid: get overlap result error
[Mon Sep 10 15:17:49 2007] [error] [client 192.168.1.21] Premature end of script headers: fastcgitest.fcgi

If I try to run as a static fastcgi, Apache refuses to start.

Any other suggestions would be appreciated.

TomW
Back to top
tomw



Joined: 10 Sep 2007
Posts: 4

PostPosted: Wed 12 Sep '07 22:02    Post subject: Reply with quote

I can get the echo examlpe from fastcgi.com to run if I build them with nmake and use the libfcgi.dll that nmake generates.

If I use Visual Studio 8 to build either the .dll or echo I get:

[Wed Sep 12 15:12:14 2007] [warn] (OS 109)The pipe has been ended. : mod_fcgid: get overlap result error
[Wed Sep 12 15:12:14 2007] [error] [client 192.168.1.21] Premature end of script headers: echo.fcgi

when I try to load the web page.

Is mod_fcgi compatible with Visual Studio 8?
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Thu 13 Sep '07 0:13    Post subject: Reply with quote

mod_fcgid (and libfcgi) is compatible with Visual Studio 8, but it is not compatible with Apache 2.2.6.
See this post and Apache bug 43329 for more info about the 2.2.6 problem.

If that is not the problem, then perhaps you are not getting the manifest into echo.exe or libfcgi.dll properly when you build with the IDE instead of NMAKE.
In your VS8 project properties, make sure you have:
    [Manifest Tool][Embed Manifest] = Yes

-tom-
Back to top


Reply to topic   Topic: mod_fcgid doesn't want to work (500) View previous topic :: View next topic
Post new topic   Forum Index -> Third-party Modules Page 1, 2  Next