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 Dumpleton).
http://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
I understand that virtualenv
allows me to have independent instances of Python and Python packages.
But how does this relate to things like Apache
, mod_wsgi
and MongoDB
?
Can these things also be included in this virtual environment?
The scenario I am interested in is being apple to have a local application that is 'self reliant' (that would be easy to install on other systems) - virtualenv
seems to enable this to an extent, but can Apache
, mod_wsgi
and MongoDB
only exist at this broader 'system level' or can they exist in a virtual environment?
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]
if path not in 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.