Ebr*_*ram 2 apache ubuntu mod-wsgi apxs2 python-3.x
我有一个用 python 3 编写的 Web API,它使用 Flask。当我从终端运行 Web API 时,代码运行良好,并且它由代码中的以下行托管。
if __name__ == '__main__':
app.run(host='', port=8010, debug='true')
Run Code Online (Sandbox Code Playgroud)
该代码运行完美,我想将其设置在 Apache 服务器上。然而,Apache 服务器已经有了使用 python 2 构建的网站,并且需要 mod_wsgi for 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) 运行时错误:“apxs”命令似乎未安装或不可执行。请检查此软件包的文档中的先决条件列表,并安装任何缺少的 Apache httpd 服务器软件包。
所以我打开了压缩包中的自述文件,发现了以下内容
如果您希望使用安装在非标准位置的 Apache 版本,您可以在执行安装之前设置
APXS环境变量并将其导出到 Apache 安装的 Apache 脚本的位置。apxs请注意,此时不会将任何内容复制到您的 Apache 安装中。因此,您不需要以 root 用户身份运行它,除非将其安装到站点范围的 Python 安装而不是 Python 虚拟环境中。
要验证安装是否成功,请使用以下 命令运行
mod_wsgi-express脚本start-server:Run Code Online (Sandbox Code Playgroud)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)
Run Code Online (Sandbox Code Playgroud)
如果有帮助的话,我正在运行 Ubuntu 12.04LTS 的服务器上执行所有这些操作。最后我的问题如下
非常感谢您的参与
带来不便敬请谅解
结果我忘了在我的 apache 服务器上安装 APXS。我只是从终端运行代码并且它起作用了
sudo apt-get apache2-threaded-dev
对于 Ubuntu 18(谢谢@MagicLAMP)
sudo apt-get install apache2-dev
Run Code Online (Sandbox Code Playgroud)
对于 Centos 7:(谢谢@User)
yum install httpd-devel
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4578 次 |
| 最近记录: |