I have configured cgi-bin and trying to run c++ object file but instead of displaying results on browser the executable file is getting downloaded.
Steps I have followed:
Steps to configure cgi-bin in public_html and public_html. Run following commands in terminal
- $ sudo a2enmod cgi
- $ sudo a2enmod cgid
- $ sudo a2enmod userdir
- $ sudo service apache2 restart
- $ mkdir ~/public_html
- $ cd ~/public_html
- $ mkdir cgi-bin
- $ cd /etc/apache2
- $ sudo vim sites-available/000-default.conf
- Add following text in file:
ScriptAlias /cgi-bin/ /home/*/public_html/cgi-bin/
<Directory "/home/*/public_html/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
SetHandler cgi-script
Order allow,deny
Allow from all
</Directory>
- $ sudo service apache2 restart
After this I have created a c++ file with this code
#include <iostream>
using namespace std;
int main ()
{
cout << "Content-type:text/html \n\n";
cout << "Hello World - First CGI Program";
return 0;
}
Compiled and linked it using this
g++ -o example example.cpp
When I am running it on browser http://localhost/~username/public_html/cgi-bin/example
The example object file is getting downloaded instead of showing result on browser.
cgi-bin
that may have your answer. – Ken Y-Nchmod a+x example
make a difference or is it alreadyrwxrwxr-x
or the like? – Ken Y-N