简体   繁体   English

如何在虚拟环境中安装 mod_wsgi

[英]How to Install mod_wsgi in a virtual Environement

Introduction简介

I have a Web API writtten in python 3 and it uses flask.我有一个用 python 3 编写的 Web API,它使用烧瓶。 The code runs fine when I run the web API from the terminal and it is hosted from the following line in the code.当我从终端运行 Web API 时,代码运行良好,并且它是从代码中的以下行托管的。

if __name__ == '__main__':
    app.run(host='', port=8010, debug='true')

Current Situation现状

The code runs perfectly and I want to set it up on an Apache Server.代码运行完美,我想在 Apache 服务器上设置它。 However the Apache server already has websites that were built using python 2 and need mod_wsgi for python 2.但是 Apache 服务器已经有使用 python 2 构建的网站,并且需要 mod_wsgi for python 2。

I looked up if there was a way to set up both mod-wsgi on the apache server but according to the following source you can't mod_wsgi for Python 2 as well as Python 3 on one Apache server我查了一下是否有办法在 apache 服务器上设置 mod-wsgi 但根据以下来源,您不能在一个 Apache 服务器上为 Python 2 和 Python 3 设置 mod_wsgi

Attempt at a solution尝试解决方案

I 'm trying to install mod-wsgi into a virtual environment.我正在尝试将 mod-wsgi 安装到虚拟环境中。 I downloaded the package from here and tried to install it into the environment after activating it.我从这里下载了该软件包,并在激活它后尝试将其安装到环境中。

I ran sudo python setup.py install from the terminal but I got the error below我从终端运行sudo python setup.py install但出现以下错误

File "setup.py", line 139, in 'missing Apache httpd server packages.'文件“setup.py”,第 139 行,位于“缺少的 Apache httpd 服务器包”中。 % APXS) RuntimeError: The 'apxs' command appears not to be installed or is not executable. % APXS) 运行时错误:“apxs”命令似乎未安装或不可执行。 Please check the list of prerequisites in the documentation for this package and install any missing Apache httpd server packages.请检查此包的文档中的先决条件列表,并安装任何缺少的 Apache httpd 服务器包。

So I opened the Read Me file that was part of zipped package and found the following所以我打开了作为压缩包一部分的自述文件,发现了以下内容

If you wish to use a version of Apache which is installed into a non standard location, you can set and export the APXS environment variable to the location of the Apache apxs script for your Apache installation before performing the installation.如果您希望使用安装到非标准位置的 Apache 版本,您可以在执行安装之前设置APXS环境变量并将其导出到 Apache apxs脚本的位置以供 Apache 安装。

Note that nothing will be copied into your Apache installation at this point.请注意,此时不会将任何内容复制到您的 Apache 安装中。 As a result, you do not need to run this as the root user unless installing it into a site wide Python installation rather than a Python virtual environment.因此,除非将其安装到站点范围的 Python 安装而不是 Python 虚拟环境中,否则您不需要以 root 用户身份运行它。

To verify that the installation was successful, run the mod_wsgi-express script with the start-server command::要验证安装是否成功,请使用start-server命令运行mod_wsgi-express脚本:

 mod_wsgi-express start-server

It seems to tackle my situation since Apache is not installed in the virtual environment that I'm running the command from but I have no idea how to do it它似乎解决了我的情况,因为 Apache 没有安装在我运行命令的虚拟环境中,但我不知道该怎么做

I presume they are talking about the setup.py file and that I should change the path but I do not know how to do it syntax wise or where my APXS script is located.我认为他们在谈论 setup.py 文件,我应该更改路径,但我不知道如何明智地进行语法或我的 APXS 脚本所在的位置。

Here is snippet of the code that I think needs to be modified这是我认为需要修改的代码片段

APXS = os.environ.get('APXS')

WITH_HTTPD_PACKAGE = False

if APXS is None:
    APXS = find_program(['mod_wsgi-apxs'],
            paths=[os.path.dirname(sys.executable)])
    if APXS is not None:
        WITH_HTTPD_PACKAGE = True

if APXS is None:
    APXS = find_program(['mod_wsgi-apxs', 'apxs2', 'apxs'],
            'apxs', ['/usr/sbin', os.getcwd()])
elif not os.path.isabs(APXS):
    APXS = find_program([APXS], APXS, ['/usr/sbin', os.getcwd()])

if not WITH_TARBALL_PACKAGE:
    if not os.path.isabs(APXS) or not os.access(APXS, os.X_OK):
        raise RuntimeError('The %r command appears not to be installed or '
                'is not executable. Please check the list of prerequisites '
                'in the documentation for this package and install any '
                'missing Apache httpd server packages.' % APXS)

The Question问题

I'm doing all of this on a server running Ubuntu 12.04LTS if it helps.如果有帮助,我将在运行 Ubuntu 12.04LTS 的服务器上执行所有这些操作。 My question at the end are the following我最后的问题如下

  1. Where is the APXS located usually in Ubuntu APXS 通常位于 Ubuntu 中的什么位置
  2. How do I change the code snippet to make use the APXS script there如何更改代码片段以在那里使用 APXS 脚本

Thank you so much for Your time非常感谢您的时间

Sorry for the inconvenience很抱歉给您带来不便

Turns out I forgot to install APXS on my apache server.原来我忘了在我的 apache 服务器上安装 APXS。 I simply ran the code from the terminal and it worked sudo apt-get apache2-threaded-dev我只是从终端运行代码,它工作sudo apt-get apache2-threaded-dev

Update更新

For Ubuntu 18 its (thank you @MagicLAMP)对于 Ubuntu 18(谢谢@MagicLAMP)

sudo apt-get install apache2-dev

For Centos 7: (thank you @User)对于 Centos 7:(谢谢@User)

yum install httpd-devel

对于 Centos 7:

yum install httpd-devel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM