I recently upgrade this (and several client servers) over to the latest release of Debian (Debian Jessie). This process went relatively smoothly apart from a couple of gotchas that came when Apache got upgraded.

One of the problems I had is that mod_python and WSGI no longer sit happily together (unless you go through some complicated rebuilding of Python, which I was unwilling to do). I needed WSGI for various things on the server, and seeing as mod_python is viewed as deprecated these days, and I only used it for trac, it made sense to migrate this.

Thankfully, this is relatively straightforward to accomplish.

Create your WSGI script

The first step is to create a python executable called trac.wsgi in your trac home directory, which you then make executable touch trac.wsgi; chown www-data:www-data trac.wsgi; chmod 700 trac.wsgi

The script will look something like:

I use one domain to host all the various trac installs, therefore this one wsgi script needs to power them all. This is what the TRAC_ENV_PARENT_DIR does. Both TRAC_ENV_PARENT_DIR and PYTHON_EGG_CACHE can take their values from the existing ones you’ve presumably already set in the apache conf (assuming you’ve already got this working with mod_python).

Updating your Apache configuration

Edit your Apache configuration and comment out or remove all the mod_python entries, e.g.

You now need to add a WSGIScriptAlias directive for whatever your TracUriRoot currently is, and modify your Directory statement to add a WSGIApplicationGroup directive, as follows:

Load WSGI

Finally, activate your module: apt-get install libapache2-mod-wsgi; a2enmod wsgi

2 thoughts on “Migrating Trac off Mod_Python

  1. I recently upgraded my webserver to Debian Jessie, which included an upgrade for Apache and PHP. This resulted in a few gotchas…
    Mod_python and WSGI don’t play nicely
    See my previous post on the subject…
    Some PHP extensions not installed
    Some PHP extensions didn’t seem to be automatically upgraded/reinstalled (these may have been ones previously only available through PECL), so:



    apt-get install php5-gnupg php5-mongo
    /etc/init.d/apache2 restart


    12

    aptget install php5gnupg php5mongo/etc/init.d/apache2 restart


    New permissions
    Apache 2.4 uses a different permissions (access / deny) arrangement than before, so you need to change these over.
    So for example, where you have:



    Order deny,allow
    Allow from all


    12

    Order deny,allowAllow from all


    You’d now have:



    Require all granted


    1

    Require all granted


    Apache have a good guide here.
    Random crashes with XCache
    If you have XCache installed, you might start getting random crashes, often with an error about:

    PHP Fatal error: Cannot redeclare class ...

    This is caused because the installer installs and activates the Zend Opcache module automatically, and you can’t run two opcode caches safely.



    php5dismod opcache; /etc/init.d/apache2 restart


    1

    php5dismod opcache; /etc/init.d/apache2 restart




    Thanks for visiting! If you’re new here you might like to read a bit about me.
    (Psst… I am also available to hire! Find out more…)


    Follow @mapkyca
    !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?’http’:’https’;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+’://platform.twitter.com/widgets.js’;fjs.parentNode.insertBefore(js,fjs);}}(document, ‘script’, ‘twitter-wjs’);


    Share this:EmailLinkedInTwitterGoogleFacebookReddit

  2. Nice try, but nope:

    [Thu Mar 28 16:29:48.129469 2019] [wsgi:error] [pid 32016:tid 139644553361152] [client xxxx:42998] mod_wsgi (pid=32016): Failed to exec Python script file ‘/data/trac/trac.wsgi’.
    [Thu Mar 28 16:29:48.129589 2019] [wsgi:error] [pid 32016:tid 139644553361152] [client xxxx:42998] mod_wsgi (pid=32016): Exception occurred processing WSGI script ‘/data/trac/trac.wsgi’.
    [Thu Mar 28 16:29:48.130017 2019] [wsgi:error] [pid 32016:tid 139644553361152] [client xxxx:42998] Traceback (most recent call last):
    [Thu Mar 28 16:29:48.130128 2019] [wsgi:error] [pid 32016:tid 139644553361152] [client xxxx:42998] File “/data/trac/trac.wsgi”, line 8, in
    [Thu Mar 28 16:29:48.130168 2019] [wsgi:error] [pid 32016:tid 139644553361152] [client xxxx:42998] import trac.web.main
    [Thu Mar 28 16:29:48.130232 2019] [wsgi:error] [pid 32016:tid 139644553361152] [client xxxx:42998] ModuleNotFoundError: No module named ‘trac’

Leave a Reply