CGI config for apache on XP

Shadow2531

[H]ard|Gawd
Joined
Jun 13, 2003
Messages
1,670
When installing perl on Windows, I usually install to c:\usr so that perl.exe is in c:\usr\bin and I install python to c:\usr\bin so that python.exe is in c:\usr\bin.

That usually solves all problems when using #!/usr/bin/perl and #/usr/bin/python.

However this time I kept the default directory of c:\perl when installing ActivePerl. Too many build scripts look for perl files in c:\perl and I found myself editing them too much to point to c:\usr\bin.

When perl and python are installed to the default directories of c:\perl and c:\python repspectively, apache cannot find perl.exe and python.exe if you use a *nix stile shebang line.

I solved the problem by adding ScriptInterpreterSource registry to httpd.conf so apache would look to the WinXP registry to find the paths. That way I can use *nix style shebang lines.

However, this does not help for the cgi extension. With the cgi extension I have to put #!/perl/bin/perl and #!/python/python or apache cannot find the interpreters.

Without installing perl and python to c:\usr\bin , how can I get the cgi extension to work right with BOTH #!/usr/bin/perl and #!/usr/bin/python ?

BTW, the paths to perl and python are set.

The problem does not exist with SSI and the shtml extension, just the cgi extension.

This is with Apache2

Thanks.
 
I suggest simply duplicating the directories. If that consumes undue space, use NTFS hard links.

(Perl and Python are evil! All CGI scripts should be compiled C++ programs! Lesser languages are unclean and lead to severe trauma or death! Repent, sinners, for the end is near!)
 
Yeh that works. Not really happy with having the duplicates, but that does work.

I've briefly read about hardlinks before. Google will instruct me on that.

As for c++, I'm curious. How do I set that up?

A sample file.exe "Hello World" program that prints out "Hello World" when I load /cgi-bin/file.exe?greeting=hello world would help.

Thanks.

edit:

I think it would be great to add the example to the tutorials thread too.
 
I got it to work with just printing "Hello World".

Code:
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(int argc) {
   double contentlength;
   const char *lsize = getenv("CONTENT_LENGTH");
   contentlength = atoi(lsize);
   cout << "Content-type: text/html\n\n";
   cout << "<html>\n<head>\n<title>test</title>\n</head>\n<body>\n<p>Hello World</p>\n";
   if (argc == 2) {
       cout << "<p>" << getenv("QUERY_STRING") << "</p>" << endl;
   }
   cout << "</body>\n</html>" << endl;
}

I probably should be using something besides atoi though.

edit:

It works if I rename the binary to file.cgi. (you are saying "of course" probably).

Anyway I changed the code above so it work print anything after the ? up to an =.

I'm looking for something like getenv("SERVER_VARIABLES") that I can store in an array, vector or some type of list.

edit:
changed the code again :)
 
You /do/ know that the stuff in parentheses was not-really-serious ranting, right?

Doing CGI in C++ is a valid question, though. Briefly, you send data to the user via cout (prefixed with headers such as "Content-type: text/plain\n\n") and you get information via getenv() in <cstdlib>.

libnuwen, which is GPLed, provides support for CGI. It is far from perfect and refined, but it works for me so far.
 
[STL]
You /do/ know that the stuff in parentheses was not-really-serious ranting, right?

Yes. Understood. I am seriously curious about c++ CGI. Even if you were completely 100% dead serious and suggested that perl and python were total crap and I should use c++ or be struck by lighting, I wouldn't just say "O.K. I'm ditching them all and just using C++.". As you have seriously suggested yourself, ~"Don't just take my word for it. Find out yourself what's correct, what's incorrect and what language is best for what you are trying to do.".

edit:

Here's what I came up with. (testing for the value of argc and doing something according was not working for "Query_String". It doesn't throw an error if there is no query string, so I got rid of the check. I also had to shove getenv("QUERY_STRING") in the test variable to do the test for greeting=hello.


Code:
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main() {
   cout << "Content-type: text/html\n\n";
   cout << "<html>\n<head>\n<title>Test</title>\n</head>\n<body>\n<div id=\"main\">\n";
   cout << "<div>Hello World</div>\n";
   cout << "<div><span style=\"font-weight: bold\">";
   string test = getenv("QUERY_STRING");
   if (test == "greeting=hello") {
       cout << "Oh, Hello!";
   }
   cout << "</span></div>\n";
   cout << "</div>\n</body>\n</html>\n";
}
 
[Shadow2531]
> I am seriously curious about C++ CGI.

As you may be aware, I am writing a forum (TranscendForum) in pure C++. It is built on top of my personal library, libnuwen, which among other things includes CGI and networking code.

It makes things like what you're trying to do, somewhat simpler. It's no Perl yet, though.
 
I've seen mention of your c++ based forum in other threads and a little on your site, but nothing too specific.
 
Setting up hardlinks for perl and python worked.

Here's what I did.

created a folder c:\usr
created a folder c:\usr\bin

at the command line:

fsutil hardlink create c:\usr\bin\perl.exe c:\perl\bin\perl.exe
fsutil hardlink create c:\usr\bin\python.exe c:\python\python.exe

CGI works perfectly and now I don't have to have the duplicates.

Thanks
 
Back
Top