I have a very simple test.py located at /var/www/html/master.com/ that I'm trying to run in Apache2, on Ubuntu 18.1
My Python code:
#!/usr/bin/env python
print("Content-type: text/html\n\n")
print("<h1>Hello</h1>")
What I have run so far:
Run a2enmod cgi to enable cgi:
ISimon@simon-EasyNote-TK85:~$ a2enmod cgi
Your MPM seems to be threaded. Selecting cgid instead of cgi.
Module cgid already enabled
Created the file cgi-enabled.conf at /etc/apache2/conf-available/, which contained the following:
# create new
# process .cgi and .py as CGI scripts
<Directory "/var/www/html/master.com">
Options + ExecCGI
AddHandler cgi-script .cgi .py
</Directory>
Restarted Apache2 with systemctl restart apache2
I then went to http://localhost/test.py and it offered to download the file. It should display as plain html.
How do I get my server configured properly?
cgi-bin. Maybe you should put code in subfoldercgi-binand run localhost/cgi-bin/test.pychmod a+x test.py. And it should haveshebang(#!) in first line to inform what program should run this code - ie,#!/usr/bin/env python.chmod a+x test.pysadly it did exactly the sameCGIbut web frameworks like Flask, Django because it is easier to write code - they have many elements which helps. And code is better organized.