Can I run Apache, mod_wsgi and MongoDB within virtualenv?

随声附和 提交于 2019-12-13 04:48:06

问题


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?


回答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]
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.



来源:https://stackoverflow.com/questions/27126694/can-i-run-apache-mod-wsgi-and-mongodb-within-virtualenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!