Python cgi-bin

I recently added a cgi-bin programme to my website (see van-maanen.com/cgi-bin/test.py). It allows me to add functionality to the website that cannot be achieved with standard html.

Most web servers have the capability to add cgi-bin functionality to its website. I have a apache web server and I had to tweak the web server to allow cgi programmes. Tweaking the web server is done by making changes to the httpd.conf.

Let me first list the changes to the httpd.conf file

  • Change the #AddHandler cgi-script .cgi line to AddHandler cgi-script .cgi .py The additional .py refers to the extension of the programmes that will be added to the website
  • Change the line Options Indexes FollowSymLinks into Options Indexes FollowSymLinks ExecCGI
  • Adjust the section that contains the properties of the directory where cgi-bin programmes will be stored: In my case Directory “C:\Users\tomva\CloudStation\htdocs\cgi-bin”. There I added SetHandler cgi-script and Options ExecCGI. This sets the security rules on the directory. If these are not set correctly, it is forbidden to access these files. One then receives the 403 error.

Restart the web server

I use Python to write programmes. This programme starts with these lines:

!"C:\Users\tomva\AppData\Local\Programs\Python\Python38\python.exe"
print("Content-type: text/html\n\n");

The first line indicates the location of Python; the second line indicates the type of output.

Door tom