paulb@390 | 1 | Configuring Apache
|
paulb@390 | 2 | ==================
|
paulb@376 | 3 |
|
paulb@376 | 4 | To configure applications without authenticators, use the config.py script
|
paulb@376 | 5 | in tools/Apache to set up mod_python applications. For example:
|
paulb@376 | 6 |
|
paulb@376 | 7 | python tools/Apache/config.py \
|
paulb@376 | 8 | mod_python \
|
paulb@376 | 9 | /home/paulb/Software/Python/WebStack/examples/ModPython/CookiesApp/CookiesHandler.py \
|
paulb@376 | 10 | /etc/apache2/sites-available \
|
paulb@376 | 11 | cookies-mod \
|
paulb@376 | 12 | /cookies \
|
paulb@376 | 13 | .cookies
|
paulb@376 | 14 |
|
paulb@390 | 15 | This script can also be used to configure CGI applications. Run the script
|
paulb@390 | 16 | without any arguments to see the documentation.
|
paulb@390 | 17 |
|
paulb@390 | 18 | With the above command, the "cookies" application should be visitable with
|
paulb@390 | 19 | URLs resembling these:
|
paulb@376 | 20 |
|
paulb@390 | 21 | http://localhost/cookies/test.cookies
|
paulb@390 | 22 | http://localhost/cookies/my.cookies
|
paulb@376 | 23 |
|
paulb@390 | 24 | The Manual Approach
|
paulb@390 | 25 | -------------------
|
paulb@376 | 26 |
|
paulb@19 | 27 | For each application, add an Alias line to httpd.conf to point to the directory
|
paulb@20 | 28 | containing the handler package, then specify the appropriate module name as the
|
paulb@19 | 29 | PythonHandler.
|
paulb@19 | 30 |
|
paulb@40 | 31 | Alias /simple "/home/paulb/Software/Python/WebStack/examples/ModPython/SimpleApp"
|
paulb@19 | 32 |
|
paulb@40 | 33 | <Directory "/home/paulb/Software/Python/WebStack/examples/ModPython/SimpleApp">
|
paulb@20 | 34 | AddHandler python-program .simple
|
paulb@20 | 35 | PythonHandler SimpleHandler
|
paulb@19 | 36 | PythonDebug On
|
paulb@19 | 37 | </Directory>
|
paulb@19 | 38 |
|
paulb@20 | 39 | It would appear that the directory really should be distinct from others
|
paulb@20 | 40 | defined for mod_python, and that the handler should have a distinct name from
|
paulb@20 | 41 | other handlers employed.
|
paulb@34 | 42 |
|
paulb@111 | 43 | The WebStack package must reside on the PYTHONPATH, along with the package
|
paulb@111 | 44 | containing the application itself. Therefore, ensure that the handler uses the
|
paulb@111 | 45 | appropriate entries in sys.path.
|
paulb@111 | 46 |
|
paulb@111 | 47 | Using the above definition in httpd.conf, only server resources residing
|
paulb@111 | 48 | directly below "/simple" in the URL "hierarchy" with names ending in ".simple"
|
paulb@111 | 49 | would be associated with the Simple WebStack application's resources.
|
paulb@111 | 50 | Therefore, the following URL paths would access the application:
|
paulb@34 | 51 |
|
paulb@34 | 52 | /simple/home.simple
|
paulb@34 | 53 | /simple/tasks.simple/my-tasks
|
paulb@34 | 54 | /simple/agenda.simple/tomorrow/first-thing
|
paulb@34 | 55 |
|
paulb@34 | 56 | Examples of URL paths not addressing the application are as follows:
|
paulb@34 | 57 |
|
paulb@34 | 58 | /agenda/my-agenda.simple
|
paulb@34 | 59 | /simple/tasks/my-tasks.simple
|
paulb@51 | 60 |
|
paulb@390 | 61 | Authentication/Authorisation in mod_python
|
paulb@390 | 62 | ==========================================
|
paulb@51 | 63 |
|
paulb@77 | 64 | Apache imposes fairly strict controls over authentication, requiring the
|
paulb@77 | 65 | addition of various declarations in the configuration in order to impose
|
paulb@77 | 66 | access controls on applications, and for WebStack authenticators to be used, a
|
paulb@77 | 67 | "PythonAuthenHandler" must be declared in the application's configuration
|
paulb@77 | 68 | section.
|
paulb@51 | 69 |
|
paulb@51 | 70 | Consequently, it is necessary to define authentication methods in the
|
paulb@51 | 71 | httpd.conf file as in the following example:
|
paulb@51 | 72 |
|
paulb@51 | 73 | Alias /auth "/home/paulb/Software/Python/WebStack/examples/ModPython/AuthApp"
|
paulb@51 | 74 |
|
paulb@51 | 75 | <Directory "/home/paulb/Software/Python/WebStack/examples/ModPython/AuthApp">
|
paulb@51 | 76 | AddHandler python-program .py
|
paulb@51 | 77 | PythonHandler AuthHandler
|
paulb@77 | 78 | PythonAuthenHandler AuthHandler
|
paulb@51 | 79 | PythonDebug On
|
paulb@51 | 80 | AuthType Basic
|
paulb@51 | 81 | AuthName "AuthResource"
|
paulb@51 | 82 | AuthUserFile /usr/local/apache2/conf/users
|
paulb@51 | 83 | require valid-user
|
paulb@51 | 84 | </Directory>
|
paulb@51 | 85 |
|
paulb@51 | 86 | The details of the application's deployment, including the exact pathname of
|
paulb@51 | 87 | the users file and the appropriate access policy, must obviously be defined
|
paulb@51 | 88 | according to the actual application concerned.
|
paulb@269 | 89 |
|
paulb@390 | 90 | Session Storage with mod_python
|
paulb@390 | 91 | ===============================
|
paulb@269 | 92 |
|
paulb@269 | 93 | The very simple SessionStore class provided in WebStack.Helpers.Session, and
|
paulb@269 | 94 | used by the WebStack.ModPython.Transaction class, requires that a directory be
|
paulb@269 | 95 | created under the Apache server root with the name "WebStack-sessions". Here are
|
paulb@269 | 96 | some example commands for doing this:
|
paulb@269 | 97 |
|
paulb@269 | 98 | cd /usr/local/apache2
|
paulb@269 | 99 | mkdir WebStack-sessions
|
paulb@269 | 100 | chown username.groupname WebStack-sessions
|
paulb@269 | 101 |
|
paulb@269 | 102 | The given "username" and "groupname" correspond to the user and group the Apache
|
paulb@269 | 103 | server assumes when running.
|