Python CGI

= Installing =

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/ /home/test/scripts/techsupp_analyzer/

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

= Test Script = sudo nano /home/test/scripts/techsupp_analyzer/cgi.py

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

= Get inputs from URL =

Create a test CGI script in cgi-bin dir: nano test.py

Make it executable: sudo chmod +x test.py

Testing: http://10.140.196.7/cgi-bin/test.py?first_name=My&last_name=Admin

= Get Inputs from Form =

File Structure: --|---index.py  | |---test.py

In the same dir as above test.py, create Form Page: nano index.py

Make it executable: sudo chmod +x index.py

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

= Javascripts =

Troubleshooting

 * If the Javascript is not loading & you are getting HTTP Error code 500 in the browser, Need to move the JS files output of the CGI-BIN directory. Every time you trying to access any file within cgi-bin path it is expecting that content will be generated by executing that file.

https://serverfault.com/questions/672189/how-do-i-prevent-apache2-from-trying-to-execute-a-file-as-a-script


 * References