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