wiki:Dev/Configuring and testing mod_python
  1. Locate the apache2 configuration file (httpd.conf or apache2.conf). In Linux, it is located in /etc/apache2/.
  2. Enable mod_python:
  • Windows users: add the following line: LoadModule? python_module modules/mod_python.so
  • Linux users: installing the package should have taken care of this. Otherwise, add the line above.
  1. Tell Apache2 that all of the files of the htdocs directory should be interpreted as python script files. The htdocs directory is part of the source code of indico (more on that later). Do this by adding:
<Directory "C:\indico\indico\code\code\htdocs">
    AddHandler python-program .py
    PythonHandler mod_python.publisher
    PythonDebug On
    PythonPath "sys.path+['c:\indico\indico\code\code']"
</Directory>

Later, change the 'Directory' and 'PythonPath?' values to what they really should be. Explanation of the lines:

  • Directory: the directory whose files you want to be interpreted as python files. In Indico, it's the htdocs directory.
  • AddHandler?: it tells apache to interpret .py files as python files.
  • PythonHander?: mod_python has several handlers available. Depending of the handler, the methods of the .py files have to be different. In Indico, we use mod_python.publisher as handler.
  • PythonDebg? On: if there is an exception, you will see the trace in your browser.
  • PythonPath?: adds the rest of the Indico classes (in other directories than htdocs) toApache's python path (not the system global path!), so that the htdocs files can call files from other directories.
  • PythonAutoReloadOff?: I don't know!
  1. Make Apache aware of the previous directory and the images directory of Indico, so that when you type for example:  http://pcituds07/indico/index.py, it knows where to look for that index.py file. Simplest way is:
Alias /indico/images "C:\indico\indico\code\resources\images"
Alias /indico "C:\indico\indico\code\code\htdocs"
  • How to test:

In the same way we have made Apache aware of the htdocs directory, we are going to create a test directory with a test python script. Add the following to your apache2.conf or httpd.conf:

<Directory "/home/david/test">
    AddHandler python-program .py
    PythonHandler mod_python.publisher
    PythonDebug On
</Directory>

Alias /test/ "/home/david/test"

Change the test directory to your liking.In the test directory create a file called test.py with the following python code:

def index(req, **params):
  return 'Hello World'

def hola (req, **params):
  return 'Hola Mundo'

You should see results if you point your browser to  http://localhost/test/test.py or  http://localhost/test/test.py/hola

  1. You need to add the following to make Apache re-route JSON-RPC requests to the json-rpc-handler.py file located in htdocs. Write it BEFORE the <Directory> entry of point 3:
<Directory "C:\indico\indico\code\code\htdocs\services">
    PythonPath "sys.path+['c:\indico\indico\code\code','c:\indico\indico\code\code\htdocs']"
    SetHandler python-program
    PythonHandler MaKaC.services.handler
    Allow from All
</Directory>

This will use the file MaKaC/services/handler.py to handle JSON requests.