I'm trying to use Python as the server-scripting language instead of PHP.
I've configured localhost and php files run fine under it.
If I create a file .../localhost/temp/test.cgi (making it executable):
#!/home/mike/python_venvs/test_venv369/bin/python print( """Content-type:text/html\n\n <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> TEST <title>My server-side template</title> </head> <body>""" ) print( "</body></html>")
... it doesn't run as a Python script: the text of the file just gets displayed in the browser.
I've done quite a bit of searching on this. I have no such file, for example, as httpd.conf. My Apache2 setup is like this: executable in /usr/sbin/apache2, with most configuration files apparently under /etc/apache2, and in particular, seemingly, /sites-available, where one finds two files, 000-default.conf and default-ssl.conf.
I may be mistaken, but I believe httpd.conf is the "old" Apache way of doing things.
I found a totally baffling but (just) possibly promising line at the bottom of 000-default.conf:
# For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf
... so I uncommented that and restarted the apache2 service. No difference.
Details of 000-default.conf
(in /etc/apache2/sites-available). NB when I was struggling to change the localhost directory changes in this file seemed to do that.
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that... ServerAdmin webmaster@localhost DocumentRoot "/media/mike/W10 D drive/My Documents/localhost" <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /media/> Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted </Directory> ...
I don't know where CGI scripts are meant to go or where they are configured (although I am about to examine the first answer below), but given that I want them to be used with the .html files under .../localhost/ as above, I want that location to be "CGI-enabled".
It turns out that a short answer to this question (specifically) was, in my case, simply to add "ExecCGI" as one of the "Options" in the
<Directory> tag or block or whatever it's called.