Configuring apache2 conf for several python web.py apps
Question: I am working on a small web dashboard -project that has backend implemented
with python's web.py framework.

The dashboard has all sorts of widget's on it, one of which also has its
backend implemented using web.py. The problem is that only one of the
designated application entry points seem to function at a time. Both the
dashboard's and the widget's apache configurations are placed in the same
file. The original configuration file (that actually worked for a while) in
apache2/conf.d/ looks like this:

    
    
    WSGIPythonPath /var/www/ProjectDASHBOARD/api
    WSGIScriptAlias /ProjectDASHBOARD/api /var/www/ProjectDASHBOARD/api/api.py/
    
    AddType text/html .py
    
    <Directory /var/www/ProjectDASHBOARD/api/>
        Order deny,allow
        Allow from all
    </Directory>
    
    
    # Stuff for graphingwidget
    
    WSGIPythonPath /var/www/ProjectDASHBOARD/widgets/graphingwidget/api
    WSGIScriptAlias /ProjectDASHBOARD/widgets/graphingwidget/api /var/www/ProjectDASHBOARD/widgets/graphingwidget/api/api.py/
    
    AddType text/html .py
    
    <Directory /var/www/ProjectDASHBOARD/widgets/graphingwidget/api/>
        Order deny,allow
        Allow from all
    </Directory>
    

This alone does not work, there is also the next piece of code that is needed
in both api.py files, checking their approriate paths and adding them if not
found (excerpt from the widget's file):

    
    
    import web
    import json
    import sys
    
    path = '/var/www/ProjectDASHBOARD/widgets/graphingwidget/api'
    if path not in sys.path:
        sys.path.append(path)
    

A similiar check is done for the dashboard.

All of this indeed worked for a whole week, and then suddenly stopped working
when trying to install from scratch, making it all the more confusing as to
what is wrong. The error received when trying to access the api from a webpage
is HTTP Error 500 Internal server error. Then after a few changes to the
apache config file ONE of the api's started working:

    
    
    WSGIPythonPath /var/www/ProjectDASHBOARD/widgets/graphingwidget/api
    WSGIPythonPath /var/www/ProjectDASHBOARD/api
    WSGIScriptAlias /ProjectDASHBOARD/api /var/www/ProjectDASHBOARD/api/api.py/
    WSGIScriptAlias /ProjectDASHBOARD/widgets/graphingwidget/api /var/www/ProjectDASHBOARD/widgets/graphingwidget/api/api.py/
    
    AddType text/html .py
    
    <Directory /var/www/ProjectDASHBOARD/api/>
        Order deny,allow
        Allow from all
    </Directory>
    
    
    # Stuff for graphingwidget
    
    AddType text/html .py
    
    <Directory /var/www/ProjectDASHBOARD/widgets/graphingwidget/api/>
        Order deny,allow
        Allow from all
    </Directory>
    

Basically just moved the paths to the beginning of the file, and switched the
order around a little bit, and suddenly one of api's start to work again.
Changing the order a little bit then makes the other api work and brakes the
other one. I don't remember the correct order for the paths, but the point is
that it used to work well, then it stopped working when installed to a fresh
identical virtual machine, and only one of the api's work depending on the
order of the paths.

Initially the configs were in different files, but it didn't work like that.
Had all kinds of errors like "Target WSGI script 'path' cannot be loaded as
Python module.", and only started to work when they were moved to the same
file.

Im thinking here that somehow one of the paths is overwritten by the other, or
that all this time the whole config has been fundamentally wrong and has been
working only by sheer luck (for a whole week, without issues...)

Any clues as to what is wrong?


Answer: Sorry for the late return, but the case was basically had to carefully RTFM at
<http://webpy.org/install#apachemodwsgi> and make use of .htaccess files.

No idea really why the solution in the original question worked as far as it
did.

