Thursday, July 10, 2008

Python CGI programming

apache configuration
/etc/httpd/conf/httpd.conf is the configuration file. Open this as root (sudo emacs -nw httpd.conf)
To enable cgis
ScriptAlias /cgi-bin/ "/var/www/cgi-bin"
<Directory "/var/www/cgi-bin">
Allow Override None
Options FollowSymLinks ExecCGI
Order allow, deny
Allow from all
<Directory>

It is also possible to set per-user cgi-bin, html folders but this reveals the users in a machine.
public_httml settings are not good for this reason

/var/www/html html folder
/var/www/cgi-bin/ cgi-bin
Must have write permissions (root or su)

AddHandler cgi-script .cgi .pl .py
Now save and start httpd by,
sudo /etc/init.d/httpd restart

File permissions
cgi-bin should be 755 (4=read, 2=write, 1=exec)
scripts should be 705 (if this needs to write to a folder then set to 707)
chmod 705 my.py

#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()

print "Content-Type: text/html \n"
print "<HTML> \n"
print "<HEAD> <TITLE> Results </TITLE> </HEAD> \n\n\n"

(At least two lines should be there after the header. If not we get Internal Server Error 500)

No comments:

Post a Comment

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1