0

介绍

我有一个用 python 3 编写的 Web API,它使用烧瓶。当我从终端运行 Web API 时,代码运行良好,它托管在代码的以下行中。

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

现在的情况

代码运行完美,我想在 Apache 服务器上设置它。然而,Apache 服务器已经有使用 python 2 构建的网站,并且需要 mod_wsgi 用于 python 2。

我查找了是否有办法在 apache 服务器上同时设置 mod-wsgi,但根据以下来源,您不能 在一个 Apache 服务器上为 Python 2 和 Python 3 设置 mod_wsgi

尝试解决方案

我正在尝试将 mod-wsgi 安装到虚拟环境中。我从这里下载了软件包,并在激活后尝试将其安装到环境中。

sudo python setup.py install从终端运行,但出现以下错误

文件“setup.py”,第 139 行,位于“缺少 Apache httpd 服务器包”中。% APXS) RuntimeError: 'apxs' 命令似乎未安装或不可执行。请检查此软件包文档中的先决条件列表并安装任何缺少的 Apache httpd 服务器软件包。

所以我打开了作为压缩包一部分的自述文件,发现以下内容

如果您希望使用安装到非标准位置的 Apache 版本,您可以在执行安装之前将APXS环境变量设置并导出到 Apache 安装的 Apache 脚本的位置。apxs

请注意,此时不会将任何内容复制到您的 Apache 安装中。因此,您不需要以 root 用户身份运行它,除非将其安装到站点范围的 Python 安装而不是 Python 虚拟环境中。

要验证安装是否成功,请 mod_wsgi-express使用以下命令运行脚本start-server::

mod_wsgi-express start-server

它似乎解决了我的情况,因为 Apache 没有安装在我从中运行命令的虚拟环境中,但我不知道该怎么做

我认为他们正在谈论 setup.py 文件,并且我应该更改路径,但我不知道如何在语法方面进行操作或我的 APXS 脚本所在的位置。

这是我认为需要修改的代码片段

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)

问题

如果有帮助,我将在运行 Ubuntu 12.04LTS 的服务器上完成所有这些工作。我最后的问题如下

  1. APXS 通常位于 Ubuntu 的哪个位置
  2. 如何更改代码片段以在那里使用 APXS 脚本

非常感谢您的参与

4

2 回答 2

3

带来不便敬请谅解

原来我忘了在我的 apache 服务器上安装 APXS。我只是从终端运行代码并且它工作 sudo apt-get apache2-threaded-dev

更新

对于 Ubuntu 18(谢谢@MagicLAMP)

sudo apt-get install apache2-dev

对于 Centos 7:(谢谢@User)

yum install httpd-devel
于 2016-07-04T15:54:36.527 回答
0

对于 Centos 7:

yum install httpd-devel
于 2020-11-12T02:42:40.867 回答