Skip to content Skip to sidebar Skip to footer

Can I Run Apache, Mod_wsgi And Mongodb Within Virtualenv?

I'm learning about virtualenv and mod_wsgi and these are my favourite articles so far: https://code.google.com/p/modwsgi/wiki/VirtualEnvironments (by the author of mod_wsgi, Graham

Solution 1:

virtualenv is for python packages only, so you cannot have instances of system applications running within in it, like apache.

Edit: As mentioned by @Graham Dumpleton, it is possible to install apache httpd using mod_wsgi-httpd inside virtualenv. But, as I said earlier virtualenv is for python packages, so it is a matter of finding/writing a package that solves the problem.

That being said, you can make Apache, that uses mod_wsgi, to take advantage of virtualenv. Trick is, configuration has to be done within a python file.

Say you are trying to setup django project myproject, that is running within virtualenv named myproject, here is your wsgi.py:

import os, sys, site

path = os.path.split(os.path.dirname(__file__))[0]
ifpathnotin sys.path:
    sys.path.append(path)

site.addsitedir('~/.virtualenvs/myproject/local/lib/python2.7/site-packages')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

activate_env=os.path.expanduser(
    "~/.virtualenvs/myproject/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Configuration for apache or mongodb wouldn't be any different, since they are system wide running services.

Post a Comment for "Can I Run Apache, Mod_wsgi And Mongodb Within Virtualenv?"