I have a local Apache2 server (installed with LAMP). The Apache2 directory is /etc/apache2
and my document root is /var/www
. Under the doc root, there's a /cgi-bin
directory, in which my script cgi.py
is. Executing with ./cgi.py
gives the desired output, but when I point my web browser to the file it offers me to download it. Apparently this is often due to an access problem, but after adding a+x
permissions to the file the problem remains.
Here's the simple script:
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
#enable debugging
import cgitb
cgitb.enable()
print("Content-Type: text/plain;charset=utf-8");
print()
print("Hello World!");
In the apache2 directory's httpd.conf
I've added the follow (it was empty prior to it):
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory /var/www/cgi-bin/>
Options ExecCGI
AddHandler cgi-script .cgi .py
</Directory>
What could be the reason the script won't execute?
EDIT: Rookie mistake, I didn't restart the server after making changes to httpd.conf
. After doing that the script executed. Thanks to Jenny D for suggesting it.