CGI downloads instead of executes!

software development


I have a CGI binary that I should be able to activate, but when I hit the URL, the browser simply tries to download the file. What should happen, is the file executes, outputs some text, and the browser downloads and interprets the text, NOT the entire file!

OK actually I dont need to hit the CGI from the browser, but actually I have a local application that needs to hit this CGI for the output. I dont think it really matters wether its the browser or the local application… In both cases the webserver is sending the CGI file itself, instead of the output from running the file.

I have spent a lot of time on this problem, and Ive seen plenty of suggestions, and have tried them all. The problem is, all the suggestions were aimed at CGI scripts, such as perl or PHP scripts, but I didnt see any suggestions specific to BINARY CGI files. I’m not sure if that makes a difference but possibly.

I’ve set the permissions of all files involved to 755. I am able to hit PHP and Perl scripts no problem. They execute and return the results to the browser. But for this binary CGI, it does NOT execute, but simply downloads.

I have seen suggestions about adding lines to the .htaccess file, but I’m not sure how to apply these suggestions to a binary file. People say to add something like
AddType text/html .cgi
To the .htaccess. But 2 problems with this: First my .CGI files are working fine already. Its my binary file that is not executing. Second, Binary files have no file extention, so how would I add a line like that to the .htaccess anyway?

My binary file definitely works and produces output. I can log into the webserver via PUTTY and run the binary locally. It spits out the correct text output that I want. How can I make this accessable over the internet??

I have a lot of experience with programming and web in general, I’m just not very experienced with linux or apache. Please help, I’m sure this is easy for most of you guys! Thanks.


Apache generally requires file extension to determine how to handle a file. On DH, files with the extension .cgi are executed by Apache. Most likely, DH’s Apache config file contains the following directive:

AddHandler cgi-script .cgi

In an .htaccess file, you can specify other extensions to run as CGI. For example:

AddHandler cgi-script .exe

The simplest solution for you is probably to just add the .cgi extension to your binary CGI programs. Then Apache will run them as CGI programs.

It may be possible to have Apache run CGI programs without extension by using the FilesMatch directive. Possibly something like this (untested):

<FilesMatch “myprogram$”>
SetHandler cg-script


Thank-you habilis !
That seems to have worked. (after fixing a slight typo in your sample - very obvious though).

I dont think I would have found that solution myself anytime soon, so thanks a lot!