Pripravak
- eventualno ćeš trebati:
apt-get install libapache2-mod-python a2enmod cginano /etc/apache2/conf-available/serve-cgi-bin.conf- unutar cjeline “
<IfModule mod_alias.c>” uredi/dodaj sljedeće:-
<Directory /var/www/html/tvojfolder> Options +ExecCGI AddHandler cgi-script .py </Directory>
-
nano /var/www/html/tvojfolder/proba.py:-
#!/usr/bin/python3 # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() print("Content-Type: text/html;charset=utf-8") print() print("Pozdrav kur.. Suncu!")
-
chmod 745 /var/www/html/tvojfolder/proba.py(ili*.pyako imaš više skripatah)service apache2 restart
Malo “kompleksniji” Python primjer:
#!/usr/bin/python3
# -*- coding: UTF-8 -*-# enable debugging
import cgitb # nemam pojma šta je ovo, radi i kad ga nema
cgitb.enable()
import time
tajmstemp =time.strftime("%Y%m%d-%H%M%S")
print("Content-Type: text/html;charset=utf-8")
print() # Ovo mora biti ovdje
hateemel=("""
<html>
<head>
</head>
<body>
Džez'ba, raja!<br>
"""+tajmstemp+"""
</body>
</html>
""")
print(hateemel)
Test
lynx http://tvojserver/tvojfolder/proba.py- Rezultat: “Pozdrav Suncu!“
apache apache2 python xapache xapache2 xpython cgi xcgi execute xexecute run xrun

