Python CGI

Installation: sudo apt-get install apache2 sudo apt-get install python3

Enable CGI processing in apache: sudo a2enmod cgi

Configure Apache2: sudo nano /etc/apache2/conf-enabled/host-cgi.conf

ScriptAlias /cgi-bin/ /var/www/html/cgi-bin/

 AllowOverride None Allow from all Require all granted Options +ExecCGI AddHandler cgi-script .py 

Create Script: sudo nano /var/www/html/cgi-bin/cgi.py


 * 1) !/usr/bin/python3


 * 1) -*- coding: UTF-8 -*-# enable debugging

import cgitb cgitb.enable print("Content-Type: text/html;charset=utf-8") print print("Hello World!")

Change Permissions: sudo chown -R test:www-data cgi-bin/ sudo chmod +x cgi-bin/cgi.bin

Testing: http://10.140.196.7/cgi-bin/cgi.py