I'm working on Ubuntu 16.04LTS with apache2. I working on executing a simple CGI python script "hello.py". But instead of executing the file, it is getting downloaded. If I change the extension from ".py" to ".cgi", the code is displaying in my browser.
My CGI script is saved in /var/www/cgi-bin directory and it is written below
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'
I have followed CGI tutorial. This tutorial is following ScriptAlias method to configure apache2. As per the tutorial, I have added the below code to the end of the apche2.conf file
######### Adding capaility to run CGI-scripts #################
ServerName localhost
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
Options +ExecCGI
AddHandler cgi-script .cgi .pl .py
And I have changed my conf-available/serve-cgi-bin.conf file into below form
<IfModule mod_alias.c>
<IfModule mod_cgi.c>
Define ENABLE_USR_LIB_CGI_BIN
</IfModule>
<IfModule mod_cgid.c>
Define ENABLE_USR_LIB_CGI_BIN
</IfModule>
<IfDefine ENABLE_USR_LIB_CGI_BIN>
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
#Require all granted
</Directory>
</IfDefine>
</IfModule>
Still my CGI script is downloading instead of running. How to solve this problem ?
LoadModule)