# [SOLVED] Apache cgi-bin Cpp help



## rstudio (Jun 9, 2012)

Hi, I would like to write some cgi-bin scripts in c++.

1. Install Apache on windows (www.apache.si//httpd/binaries/win32/httpd-2.2.22-win32-x86-no_ssl.msi) 

2. Then I create test.cgi file in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\cgi-bin

3. Open file with note pad and write Helo world program.


#include<iostream>
using namespace std;

int main()
{
cout<<"Helllo"<<endl;
return 0;
}

4. Open http://localhost/cgi-bin/test.cgi web address and I get 500 internal server error.
Log:
[Thu Jun 21 13:33:05 2012] [error] [client 127.0.0.1] C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/test.cgi is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Thu Jun 21 13:33:05 2012] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/test.cgi

5. So I add #! at start of file
Log:
[Thu Jun 21 13:36:55 2012] [error] [client 127.0.0.1] (OS 193)%1 is not a valid Win32 application. : couldn't create child process: 720193: test.cgi
[Thu Jun 21 13:36:55 2012] [error] [client 127.0.0.1] (OS 193)%1 is not a valid Win32 application. : couldn't spawn child process: C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/test.cgi

6. Then I compiled this program in CodeBlocks and copy test.exe file in cgi-bin directory
Log:
[Thu Jun 21 13:59:15 2012] [error] [client 127.0.0.1] malformed header from script. Bad header=Helllo: test.exe

7...

So what I'm doing wrong?


----------



## rstudio (Jun 9, 2012)

*Re: Apache cgi-bin Cpp help*

Corect way is to compile .cpp file with -O parameter (optimize for speed) And then move .exe file to cgi-bin folder.
you run .exe with this link:
http://localhost/cgi-bin/test.exe


----------

