Redhat – Multiple python versions under apache+mod_wsgi

apache-2.2mod-wsgipythonredhatvirtualhost

I have several virtual hosts configured under the same apache instance on redhat:

  • apache-2.2.15
  • mod_wsgi-3.5 compiled with default system python-2.6

For every virtual host WSGIScriptAlias setting is pointed to the python file where the virtual environment is activated:

activate_this = '/path_to_the_virtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

Now, I'm planning to upgrade one of the projects to python-2.7, another one to python-3.x. I know that I can have different virtual environments, separate python sandboxes. So, everything is good on the python side.

The question is: is it possible to use different python versions for different apache virtual hosts under the same apache+mod_wsgi instance?

If not, what would be the best option to proceed?

There is a relevant WsgiPythonHome setting, but it is defined globally in the "server config" context, not per virtual host. Plus, mod_wsgi is compiled for the specific python version, so I'm not sure it can handle the case.

Best Answer

No it isn't possible. The mod_wsgi binary has to be compiled against one Python version only and only one instance of a compiled mod_wsgi module can be loaded into Apache at a time.

What you would need to do is setup Apache to proxy to a separate WSGI server listening on its own ports.

To use Apache/mod_wsgi as that backend server as well, you would want to investigate using mod_wsgi 4.1.X. See:

This newer version of mod_wsgi provides a way of installing mod_wsgi against multiple Python versions and running up an Apache instance for each using a provided script. The script takes over all the setup of the Apache configuration so you do not need to worry about it.