Sample code/Python/Hello World

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:

index-file.names           = ( "index.php", "index.html", "index.py",                                "index.htm", "default.htm" )
 * 1) files to check for if .../ is requested

Where "index.py", was added to the index-file.names.

Then, add ".py" as a static-file.exclude-extension: static-file.exclude-extensions = ( ".php", ".pl",".py", ".fcgi" )
 * 1) .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi

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

Load the module for cgi interface in /etc/lighttpd/modules.conf, uncommenting the line: include "conf.d/cgi.conf"

Test to see if the config file works: Syntax OK
 * 1) lighttpd -tf /etc/lighttpd.conf

Finally, start lighttpd:
 * 1) lighttpd -f /etc/lighttpd.conf

To restart lighttpd, use ps to find the process ID: 1337 root       884 S   lighttpd -f /etc/lighttpd.conf 1342 root       136 R   grep lighttpd
 * 1) ps | grep lighttpd

Then, kill the process:
 * 1) kill 1337

Finally, restart lighttpd.
 * 1) 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.