- Why Use mod_python
- Basic configuring
- Solving problems for non-root-mounted wikis
- Configuring root wiki
- Older mod_python versions
Why Use mod_python
mod_python embeds the python interpreter into the apache server. This saves initialization time and the need of forking cgi scripts. It doesn't have the ability to run as different users. It will always run as the main apache user and group. Be sure that your wiki data files are accessible and writable by your apache server.
mod_python will cause your apache processes to increase their memory requirements considerably - especially as apache runs many separate processes which will each need to have their own copy of the python code and data in the process memory space. You may find that FastCGI, as detailed in HelpOnInstalling/ApacheWithFastCgi is rather more efficient in this respect.
The sample configurations below are for a wiki instance called mywiki installed in a directory /var/www/moin/mywiki with the main MoinMoin installation installed in python's default site library path. The wiki appears as URL /mywiki under the server - ie http://my.ser.ver/mywiki. You will need to change these to reflect your installation.
Most people will just add a mod_python package to their current operating system installation. If you are building from source then you should consult the mod_python documentation.
The mod_python installation should have added some lines to the Apache configuration file - either in the file itself or in an included configuration file (for example on Red Hat or Fedora linux the mod_python configuration is in /etc/httpd/conf.d/python.conf).
[Sat Jan 01 15:40:49 2005] [notice] mod_python: Creating 4 session mutexes based on 150 max processes and 0 max threads.
Set up a wiki instance
This is done as shown in WikiInstanceCreation. Its recommended to first configure the wiki with cgi and check that it works, then change the configuratin to use mod_python. This allows you be sure that any problems are in the mod_python transition rather than the basic MoinMoin installation.
import os data_dir = os.path.join(os.path.dirname(__file__), 'data/') data_underlay_dir = os.path.join(os.path.dirname(__file__), 'underlay/')
Changes to Apache `httpd.conf`
If you run your wiki as cgi as we recommended before, remove or comment the ScriptAlias directive:
<Location /mywiki> SetHandler python-program # Add the path of your wiki directory PythonPath "['/var/www/moin/mywiki'] + sys.path" PythonHandler MoinMoin.request::RequestModPy.run </Location>
If you have multiple MoinMoin instances then add one location directive for each one (changing the paths as appropriate) and add a line with the directive PythonInterpreter mywiki to each Location section. With this directive different subinterpreters with completely separate namespaces will be used for each wiki (see here for details).
Solving problems for non-root-mounted wikis
On some installations, mod_python hands MoinMoin incorrect script_name and path_info. It usually happens when using the Apache Location directive, with a wiki in an arbitary path:
<Location /farm/mywiki> # Location value must match the Apache Location value! PythonOption Location /farm/mywiki ... </Location>
Configuring root wiki
You may wish to have your wiki appearing at the root of your webserver - for example so that http://wiki.example.com/ will map to your wiki rather than having to use http://wiki.example.com/mywiki/. This requires a slightly different form of configuration using mod_rewrite - this is a standard module of recent Apache distributions, and is often enabled by default.
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot /var/www/html ServerName wiki.example.com Alias /wiki/ "/usr/share/moin/htdocs/" # Rewrite urls RewriteEngine On RewriteLogLevel 0 # map /wiki static files to Moin htdocs RewriteRule ^/wiki/(.*)$ /usr/share/moin/htdocs/$1 [last] # map everything else to server script RewriteRule ^(.*)$ /var/www/moin/mywiki/moinmodpy.py$1 <Directory "/var/www/moin/testwiki"> # Modpy stuff AddHandler python-program .py # Add the path to the wiki directory, where # moinmodpy.py and wikiconfig.py are located. PythonPath "['/var/www/moin/mywiki'] + sys.path" PythonHandler moinmodpy </Directory> </VirtualHost>
Other ways of handling root level wikis with Apache are detailed in the appropriately named HelpOnConfiguration/ApacheVoodoo.
Older mod_python versions
mod_python versions 2.7.10, 3.0.4 and 3.1.2b have a bug in apache.resolve_object. This bug was reported to the mod_python maintainers and has been fixed in the 3.1.3 release. The best fix for this is to update to the current release. However if you are unable to do this there are 2 possible solutions:
Use a wrapper script
MoinMoin come with a moinmodpy.py wrapper script, and this could be used by changing the PythonPath and PythonHandler directives as shown in the moinmodpy.htaccess file. The wrapper was named moin_modpy.py in MoinMoin 1.2.
PythonHandler MoinMoin.request::RequestModPy.run: OSError: [Errno 2] No such file or directory: 'data/user' This appears to be caused by you not having an absolute path for data_dir in moin_config.py. There are several other lines of error traceback preceding this one in the apache error log. Fix the path in moin_config.py.