如何在CentOS 7上使用python3.5为apache 2.4+安装mod_wgsi

时间:2017-02-02 14:36:14

标签: apache python-3.x centos mod-wsgi

正如标题所说"如何在CentOS 7和#34上安装python3.5的mod_wgsi?

$ pip3.5安装mod_wgsi无法正常工作

Collecting mod_wgsi
  Could not find a version that satisfies the requirement mod_wgsi (from versions: )
No matching distribution found for mod_wgsi

sudo yum install libapache2-mod-wsgi-py3也失败了:

Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirror.daniel-jost.net
 * epel: mirrors.n-ix.net
 * extras: mirror.daniel-jost.net
 * ius: mirror.amsiohosting.net
 * remi: mirror.23media.de
 * remi-php56: mirror.23media.de
 * remi-safe: mirror.23media.de
 * updates: mirror.daniel-jost.net
No package libapache2-mod-wsgi-py3 available.
Error: Nothing to do

非常欢迎任何关于如何在CentOS 7上运行apache2.4 + mod_wsgi和python3.5的建议!

4 个答案:

答案 0 :(得分:7)

我看到你已经启用了IUS repo。

可以安装正常的软件包,而不是跳过SCL篮球
yum install python35u-mod_wsgi

这将使用标准文件系统位置来处理Apache HTTPD 2.4。

/etc/httpd/conf.modules.d/10-wsgi-python3.5.conf
/usr/lib64/httpd/modules/mod_wsgi_python3.5.so

答案 1 :(得分:2)

我尝试关注Carl's answer,但并不能解决问题。事实证明,我安装的版本在安装后需要一些额外的配置步骤。

背景

在安装modules升级之前,我查看了Apache的mod_wsgi文件夹:

$ ls -l /lib64/httpd/modules
[...]
-rwxr-xr-x. 1 root root 172800 Oct 30 22:44 mod_wsgi.so

然后,我安装了SCL存储库,并查看了mod_wsgi的哪些版本可用。

$ sudo yum install -q -y centos-release-scl
[...]
$ yum search mod_wsgi
[...]
koschei-frontend.noarch : Web frontend for koschei using mod_wsgi
mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python27-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python33-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python34-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python35-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python36-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
viewvc-httpd-wsgi.noarch : ViewVC configuration for Apache/mod_wsgi
[...]

我正在使用Python 3.6,因此我安装了匹配的版本并重新启动了Apache。

$ sudo yum install -q -y rh-python36-mod_wsgi
[...]
$ sudo systemctl restart httpd

遗憾的是,这并不能解决问题。当我查看Apache的modules文件夹时,没有任何改变。奇怪!

$ ls -l /lib64/httpd/modules
[...]
-rwxr-xr-x. 1 root root 172800 Oct 30 22:44 mod_wsgi.so

那安装了什么?

$ rpm -ql rh-python36-mod_wsgi
/opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf
/opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/CREDITS.rst
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/LICENSE
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/README.rst

其他配置步骤

它安装了我需要的文件,但没有将它们放在有用的地方。借助README.rst文件中的一些提示,我将它们复制到了正确的位置。

sudo cp /opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so /lib64/httpd/modules
sudo cp /opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf /etc/httpd/conf.modules.d
sudo systemctl restart httpd

现在,我拥有mod_wsgi的正确版本,并且我的Django应用将在Apache下运行。

答案 2 :(得分:1)

您是否检查了提供rh-python35-mod_wsgi包的 rh-python35 软件集合?

有关SCL的更多信息,请参阅:

答案 3 :(得分:0)

我会使用SCL packages for python 3.6(尽管可以用下面的3.5代替)。

要开始:

yum install centos-release-scl
yum install rh-python36 rh-python36-mod_wsgi

请注意,这将引入SCL软件包httpd24-httpd,并将mod_wsgi文件放入该安装中。我建议您使用该安装,而不安装基本的CentOS httpd软件包。在撰写本文时,对于CentOS 7,httpd软件包是2.4.6,而httpd24-httpd软件包是2.4.37。

然后您使用以下命令创建一个virtualenv:

/opt/rh/rh-python36/root/usr/bin/python -m venv /path/to/venv36
source /path/to/venv36/bin/activate
pip install ...

现在,您可以将网站的配置放在/opt/rh/httpd24/root/etc/httpd/conf.d/mysite.conf中,其中可能包含以下内容:

<VirtualHost *:80>
    LoadModule wsgi_module modules/mod_wsgi.so

    ErrorLog /var/log/httpd24/mysite-err.log
    CustomLog  /var/log/httpd24/mysite.log combined

    # recommended way of setting DJANGO_SETTINGS_MODULE http://stackoverflow.com/a/25496668/3189
    WSGIProcessGroup mysite.settings.production
    WSGIDaemonProcess mysite.settings.production python-path=/path/to/mysite/:/path/to/venv36/lib/python3.6/site-packages
    WSGIScriptAlias / /path/to/mysite/wsgi.py process-group=mysite application-group=%{GLOBAL}
</VirtualHost>

现在,您使用以下命令启动SCL Apache:

systemctl start httpd24-httpd

您的网站应该可以正常工作。