Python CGI: Difference between revisions
(Created page with "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-...") |
m (Protected "Apache CGI" ([Edit=Allow only logged in users] (indefinite) [Move=Allow only logged in users] (indefinite) [Delete=Allow only logged in users] (indefinite))) |
(No difference)
|
Revision as of 22:23, 12 December 2018
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/ <Directory /var/www/html/cgi-bin> AllowOverride None Allow from all Require all granted Options +ExecCGI AddHandler cgi-script .py </Directory>
Create Script:
sudo nano /var/www/html/cgi-bin/cgi.py
#!/usr/bin/python3 # -*- 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