I have an apache 2.4.46-3 server, which serves out of /srv/http. I have a folder /srv/http/bin with 2 files:

.htacces (mode 644):

AddHandler cgi-script .exe
Options +ExecCGI

main.exe (mode 755): compiled from main.cpp:

#include <iostream>
using namespace std;

int main () {
   cout << "Content-type:text/html\r\n\r\n";
   cout << "<html>\n";
   cout << "<head>\n";
   cout << "<title>Hello World - First CGI Program</title>\n";
   cout << "</head>\n";
   cout << "<body>\n";
   cout << "<h2>Hello World! This is my first CGI program</h2>\n";
   cout << "</body>\n";
   cout << "</html>\n";
   return 0;

But when I visit the page localhost/bin/main.exe, it offers to download the exe instead of displaying the html. Did I forget to enable something?


Problem with cgi-bin directory this did NOT solve my issue!

Replacing all instances of exe with cgi also did not solve my issue!


<Directory "/srv/http/bin">
    Options +ExecCGI
    AddHandler cgi-script cgi pl exe
    AllowOverride All
    Require all granted

To httpd.conf also did NOT solve the issue! There are no errors in /var/log/httpd/error_log related to cgis or exes or the /srv/http/bin folder, so what could be going on here?


It turns out I did not have the cgi module loaded in httpd.conf.

Here is the relevant configuration (search for "cgi_module" in your config):

<IfModule !mpm_prefork_module>
        LoadModule cgid_module modules/mod_cgid.so
<IfModule mpm_prefork_module>
        LoadModule cgi_module modules/mod_cgi.so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.