paulb@389 | 1 | Configuring Apache
|
paulb@389 | 2 | ==================
|
paulb@376 | 3 |
|
paulb@376 | 4 | To configure applications without authenticators, use the config.py script
|
paulb@389 | 5 | in tools/Apache to set up CGI applications. For example:
|
paulb@376 | 6 |
|
paulb@376 | 7 | python tools/Apache/config.py \
|
paulb@376 | 8 | CGI \
|
paulb@376 | 9 | /home/paulb/Software/Python/WebStack/examples/CGI/CookiesApp.py \
|
paulb@376 | 10 | /etc/apache2/sites-available \
|
paulb@376 | 11 | cookies \
|
paulb@376 | 12 | /cgi/cookies
|
paulb@376 | 13 |
|
paulb@389 | 14 | This script can also be used to configure mod_python applications. Run the
|
paulb@389 | 15 | script without any arguments to see the documentation.
|
paulb@376 | 16 |
|
paulb@389 | 17 | With the above command, the "cookies" application should be visitable with a
|
paulb@389 | 18 | URL resembling this one:
|
paulb@376 | 19 |
|
paulb@389 | 20 | http://localhost/cgi/cookies
|
paulb@389 | 21 |
|
paulb@389 | 22 | The Manual Way
|
paulb@389 | 23 | --------------
|
paulb@376 | 24 |
|
paulb@114 | 25 | Declare the script in httpd.conf or equivalent Web server configuration file.
|
paulb@114 | 26 | For example:
|
paulb@114 | 27 |
|
paulb@114 | 28 | ScriptAlias /cgi/simple "/home/paulb/Software/Python/WebStack/examples/CGI/SimpleHandler.py"
|
paulb@114 | 29 |
|
paulb@114 | 30 | The WebStack package must reside on the PYTHONPATH, along with the package
|
paulb@114 | 31 | containing the application itself. Therefore, ensure that the handler uses the
|
paulb@114 | 32 | appropriate entries in sys.path.
|
paulb@114 | 33 |
|
paulb@114 | 34 | Ensure that the handler file for the application has the appropriate
|
paulb@114 | 35 | permissions:
|
paulb@114 | 36 |
|
paulb@114 | 37 | chmod u+x examples/CGI/SimpleHandler.py
|
paulb@269 | 38 |
|
paulb@389 | 39 | With the above configuration, the "cookies" application should be visitable
|
paulb@389 | 40 | with a URL resembling this one:
|
paulb@389 | 41 |
|
paulb@389 | 42 | http://localhost/cgi/simple
|
paulb@389 | 43 |
|
paulb@389 | 44 | Configuring AOLserver
|
paulb@389 | 45 | =====================
|
paulb@389 | 46 |
|
paulb@443 | 47 | NOTE: AOLserver does not seem to handle "URL encoded" character values
|
paulb@443 | 48 | NOTE: properly when such values appear in the path before the query string.
|
paulb@443 | 49 |
|
paulb@389 | 50 | To configure applications for AOLserver, edit the server's configuration file
|
paulb@406 | 51 | (eg. config.tcl) so that definitions similar to the following are present in
|
paulb@406 | 52 | the "CGI interface" section:
|
paulb@389 | 53 |
|
paulb@389 | 54 | ns_section "ns/server/${servername}/module/nscgi"
|
paulb@443 | 55 | ns_param map "GET /cgi/simple /home/paulb/Software/Python/WebStack/examples/CGI/SimpleHandler.py" ;# CGI script file (GET).
|
paulb@443 | 56 | ns_param map "POST /cgi/simple /home/paulb/Software/Python/WebStack/examples/CGI/SimpleHandler.py" ;# CGI script file (POST).
|
paulb@389 | 57 | ns_param interps CGIinterps
|
paulb@389 | 58 |
|
paulb@389 | 59 | ns_section "ns/interps/CGIinterps"
|
paulb@389 | 60 | ns_param .py "/usr/bin/python"
|
paulb@269 | 61 |
|
paulb@389 | 62 | Search for the first line in the definitions above and add the following lines
|
paulb@389 | 63 | immediately after it in the file.
|
paulb@389 | 64 |
|
paulb@389 | 65 | Additionally, in the "Modules to load" section, starting with this line...
|
paulb@389 | 66 |
|
paulb@389 | 67 | ns_section "ns/server/${servername}/modules"
|
paulb@389 | 68 |
|
paulb@389 | 69 | ...you must ensure that the nscgi.so module is enabled:
|
paulb@389 | 70 |
|
paulb@389 | 71 | ns_param nscgi ${bindir}/nscgi.so
|
paulb@389 | 72 |
|
paulb@389 | 73 | In other words, it must not be commented out with a leading # character.
|
paulb@389 | 74 |
|
paulb@443 | 75 | With the above configuration, the example application should be visitable with
|
paulb@443 | 76 | a URL resembling one of these:
|
paulb@389 | 77 |
|
paulb@443 | 78 | http://192.168.1.100/cgi/simple
|
paulb@443 | 79 | http://192.168.1.100:8000/cgi/simple
|
paulb@389 | 80 |
|
paulb@443 | 81 | (Where 192.168.1.100 is the address that AOLserver is listening on - it does
|
paulb@443 | 82 | not seem to enjoy listening on localhost.)
|
paulb@389 | 83 |
|
paulb@406 | 84 | Configuring lighttpd
|
paulb@406 | 85 | ====================
|
paulb@406 | 86 |
|
paulb@406 | 87 | To configure applications for lighttpd, edit the server's configuration file
|
paulb@406 | 88 | (eg. lighttpd.conf) so that definitions similar to the following are present:
|
paulb@406 | 89 |
|
paulb@406 | 90 | alias.url = ( "/cgi/" => "/home/paulb/Software/Python/WebStack/examples/CGI/" )
|
paulb@406 | 91 | cgi.assign = ( ".py" => "" )
|
paulb@406 | 92 |
|
paulb@406 | 93 | The latter line assumes that the permissions of the handler programs (eg.
|
paulb@406 | 94 | SimpleHandler.py) are set correctly and that the first line of the programs
|
paulb@406 | 95 | declares the Python runtime's whereabouts; for example:
|
paulb@406 | 96 |
|
paulb@406 | 97 | #!/usr/bin/env python
|
paulb@406 | 98 |
|
paulb@406 | 99 | To associate a specific Python runtime executable with the .py suffix, use a
|
paulb@406 | 100 | line like the following instead:
|
paulb@406 | 101 |
|
paulb@406 | 102 | cgi.assign = ( ".py" => "/usr/bin/python" )
|
paulb@406 | 103 |
|
paulb@406 | 104 | More advanced configuration of lighttpd to expose "cleaner" names for
|
paulb@406 | 105 | application resources is not covered here.
|
paulb@406 | 106 |
|
paulb@389 | 107 | Session Storage with CGI
|
paulb@389 | 108 | ========================
|
paulb@269 | 109 |
|
paulb@269 | 110 | The very simple SessionStore class provided in WebStack.Helpers.Session, and
|
paulb@389 | 111 | used by the WebStack.CGI.Transaction class, requires that a directory be
|
paulb@389 | 112 | created in the directories of the CGI programs being run with the name
|
paulb@269 | 113 | "WebStack-sessions". Here are some example commands for doing this:
|
paulb@269 | 114 |
|
paulb@269 | 115 | cd examples/CGI
|
paulb@269 | 116 | mkdir WebStack-sessions
|
paulb@269 | 117 | chown username.groupname WebStack-sessions
|
paulb@269 | 118 |
|
paulb@389 | 119 | The given "username" and "groupname" correspond to the user and group the Web
|
paulb@269 | 120 | server assumes when running.
|