我可以运行的virtualenv内阿帕奇,mod_wsgi的和MongoDB? [英] Can I run Apache, mod_wsgi and MongoDB within virtualenv?
问题描述
我在学习的virtualenv
和的mod_wsgi
键,这些都是我最喜欢的文章至今:
I'm learning about virtualenv
and mod_wsgi
and these are my favourite articles so far:
的https://$c$c.google.com/p/ modwsgi /维基/ VirtualEnvironments 结果
(由的mod_wsgi
的作者格雷厄姆邓普尔顿)。
https://code.google.com/p/modwsgi/wiki/VirtualEnvironments
(by the author of mod_wsgi
, Graham Dumpleton).
http://www.dabapps.com/blog /引进到PIP-和virtualenv中,蟒蛇/
据我所知,的virtualenv
让我有Python和Python包的独立实例。
I understand that virtualenv
allows me to have independent instances of Python and Python packages.
但这是如何涉及到的东西像的Apache
,的mod_wsgi
和的MongoDB
?
But how does this relate to things like Apache
, mod_wsgi
and MongoDB
?
可以把这些东西也可以包含在这个虚拟环境?
Can these things also be included in this virtual environment?
我感兴趣的方案是为苹果有一个本地应用程序是自力更生(这将是易于安装在其他系统上) - 的virtualenv
似乎使这在一定程度上,但的Apache
,的mod_wsgi
和的MongoDB
只有在这个更广阔的系统级存在,或者他们可以在虚拟环境中存在吗?
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
是Python包而已,<击>所以你不能有内运行的系统应用实例在这里面,比如Apache 击>。
virtualenv
is for python packages only, so you cannot have instances of system applications running within in it, like apache.
修改:由于@Graham邓普尔顿提到的,可以使用安装apache httpd的的的mod_wsgi的httpd 内的virtualenv
。但是,正如我刚才所说的virtualenv是Python包,所以它是寻找/写一个解决问题的一揽子问题。
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.
话虽这么说,你可以让Apache,使用的mod_wsgi,利用的virtualenv
的。诀窍是,配置必须Python文件内完成。
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.
假设你正在试图安装Django项目的myproject
,名为的virtualenv 的myproject
中运行,这里是你的 wsgi.py
:
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()
对于Apache或MongoDB的配置也不会有任何不同,因为它们是系统运行的广泛的服务。
Configuration for apache or mongodb wouldn't be any different, since they are system wide running services.
这篇关于我可以运行的virtualenv内阿帕奇,mod_wsgi的和MongoDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!