Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XP, Apache 2, C++ CGI

Status
Not open for further replies.

kodr

Programmer
Dec 4, 2003
368
I'm trying to set up a server for internal testing, and I am missing something.

I keep getting an internal server error 500 everytime I try to test a simple C++ cgi script.

Can anyone point me in the right direction for a set up tutorial or example for this type of thing? Is there anything common that I might have missed to get this working?

Thanks.
 
Hi

I am quite sure your problem is not in Apache and belongs to forum452. But to be sure, could you post the source code of that C++ program ? And please confirm that it is indeed a program, and not interpreted as script.

Feherke.
 
Here's the source code:

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

using namespace std;

int main()
{
    time_t currentTime; // variable for storing time
    cout << "Content-Type: text/html\n\n"; // output http header
    
    // output XML declaration and DOCTYPE
    cout << "<?xml version = \"1.0\"?>"
         << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
         << "\"[URL unfurl="true"]http://www.w3c.org/TR/xhtml11/DTD/xhtml11.dtd\">";[/URL]
         
    time( &currentTime ); // store time in currentTime
    
    // output html element and some of its contents
    cout << "<html xmlns = \"[URL unfurl="true"]http://www.w3c.org/1999/xhtml\">"[/URL]
         << "<head><title>Current date and time</title></head>"
         << "<body><p>" << asctime( localtime( &currentTime ) )
         << "</p></body></html>";
    
    
    return 0;
}

I've compiled this, and placed the file in my cgi-bin folder (and renamed the extension to .cgi)
 
Here's what I sometimes use:


It's older, but seems to work well for non-M$ (visual) developement.

Now, you said to make sure that the following is not active?
Code:
AddHandler cgi-script .cgi

That seems kind of counter-intuitive to me. But I'll give it a try.
 
Figures it would be something simple. I can't test this until I get home (I shut the server down.)

I was having trouble finding documentation on setting up the environment under windows, so I was trying to work off of some Linux tutorials.
 
Thanks.

So on a Windows platform, you leave the extension as .exe, correct?
 
Hi

Yes. The web server just runs it, the same way you would run it from the command line. There is not internal handling for executables. So the web server's requirement to run a file includes the operating system's requirement too.

If you not want to expose the file type to let everybody know that you use an .exe, you can mask it with a rewrite :
Code:
RewriteEngine on

RewriteRule (.*)\.kodr$ /cgi-bin/$1.exe
Of course, you can use any extension instead of .kodr, just make sure it will not clash with a legitimate extension you use and Apache knows.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top