Sample code/Python/Hello World
From GumstixDocsWiki
This page presents a Python variation of the classic "Hello World" program.
The source
The source code for the Hello World program (hello.py) is presented here:
print "Hello World!"
Enabling the lighttpd webserver for use with Python
See the PHP Hello World example for information on how to initially configure lighttpd.
To have lighttpd support python scripts, open lighttpd.conf on the gumstix board. I use nano to edit the lighttpd.conf file.
nano /etc/lighttpd.conf
To have index.py as a default web-script do the following:
# files to check for if .../ is requested
index-file.names = ( "index.php", "index.html", "index.py",
"index.htm", "default.htm" )
Where "index.py", was added to the index-file.names.
Then, add ".py" as a static-file.exclude-extension:
# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi static-file.exclude-extensions = ( ".php", ".pl",".py", ".fcgi" )
Add the following below under the appropriate part of the document:
cgi.assign = ( ".py" => "/usr/bin/python")
Replace /usr/bin/python with where python is located within your file system. For multiple cgi assignments, such as python and php, you can do the following:
cgi.assign = ( ".py" => "/usr/bin/python",
".php" => "/usr/bin/cgi-php")
Save and exit:
ctrl-x y <enter>
Test to see if the config file works:
# lighttpd -tf /etc/lighttpd.conf Syntax OK
Finally, start lighttpd:
# lighttpd -f /etc/lighttpd.conf
To restart lighttpd, use ps to find the process ID:
# ps | grep lighttpd 1337 root 884 S lighttpd -f /etc/lighttpd.conf 1342 root 136 R grep lighttpd
Then, kill the process:
# kill 1337
Finally, restart lighttpd.
# lighttpd -f /etc/lighttpd.conf
Using hello.py
Upload hello.php to the gumstix folder /www/pages and change the permissions. (See the PHP Hello World page for the configuration information of lighttpd.)
chmod 755 /www/pages/hello.py
With lighttpd running, navigate your browser to the gumstix ip address:
http://ip_address:port/hello.py/ i.e. http://192.168.167.16:82/hello.py/
The default port is 80 but that can be changed in lighttpd.conf.

