不能 运行 Apache2 和 virtualenv
Can't run Apache2 with virtualenv
我正在做一个基于Django的网站,在服务器上安装了一个Python 3.5,但是我的项目需要一个Python 3.6。我决定使用 virtualenv。我成功安装了所需的 Python 版本,但我无法使用 virtualenv
.
使其与 Apatche2 一起使用
网站只能在 Python 2.7 上 运行 ,否则没有任何反应,页面加载很长时间没有任何错误。
这是我的 VirtualHost 配置,我尝试在 Python 3.6.
上 运行
<VirtualHost *:443>
ServerName <site_adress>:443
ServerAdmin admin@<site_adress>
DocumentRoot /var/www/html/MMServer
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/custom.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/mm.cert
SSLCertificateKeyFile /etc/apache2/ssl/mm.key
Alias /static/ /var/www/html/MMServer/static/
<Directory /var/www/html/MMServer/static>
Require all granted
</Directory>
WSGIDaemonProcess MMServer python-path=/var/www/html/MMServer python-home=/var/www/html/venv
WSGIProcessGroup MMServer
WSGIScriptAlias / /var/www/html/MMServer/mm_server/wsgi.py
<Directory /var/www/html/MMServer/mm_server>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
下面是我的 wsgi.py
文件:
import os
import sys
def application(environ, start_response):
start_response('200 OK',[('Content-type','text/html')])
return [sys.version]
只有一件事我可以通过这种方式获得(同时 WSGIDaemonProcess
和 WSGIProcessGroup
被删除)是:
2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]
编辑 1:
有可能我缺少软件包,因为我重新安装了 python 3.5,需要哪些软件包才能工作?
解决方案:
我做了两件事,我不确定是什么对我有帮助,但首先我禁用了 mod (a2dismod wsgi
) 并删除了一个包 libapache2-mod-wsgi
.
选项 1:
apt-get install libapache2-mod-wsgi-py3
选项 2:
我从源安装了一个mod-wsgi
:
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.3.tar.gz
tar -xf 4.6.3.tar.gz
./configure --with-python=/usr/local/bin/python3.6
make
make install
现在一切正常。
谢谢@Graham Dumpleton,你的回答很有帮助。
mod_wsgi 模块是链接到 Python 库的 C 代码。因此,它编译的 Python 版本嵌入在模块中。它不只是执行 python
程序。这意味着它必须针对您要使用的 Python 版本进行编译。您不能通过虚拟环境强制它使用不同的 Python 版本。关于在虚拟环境中使用 mod_wsgi 的文档中对此进行了说明。
简而言之,您需要卸载mod_wsgi模块(可能是操作系统打包的),并从源代码中自行安装mod_wsgi,针对Python版本进行编译你想用。最简单的方法是使用 pip install
方法。
我正在做一个基于Django的网站,在服务器上安装了一个Python 3.5,但是我的项目需要一个Python 3.6。我决定使用 virtualenv。我成功安装了所需的 Python 版本,但我无法使用 virtualenv
.
使其与 Apatche2 一起使用
网站只能在 Python 2.7 上 运行 ,否则没有任何反应,页面加载很长时间没有任何错误。
这是我的 VirtualHost 配置,我尝试在 Python 3.6.
<VirtualHost *:443>
ServerName <site_adress>:443
ServerAdmin admin@<site_adress>
DocumentRoot /var/www/html/MMServer
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/custom.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/mm.cert
SSLCertificateKeyFile /etc/apache2/ssl/mm.key
Alias /static/ /var/www/html/MMServer/static/
<Directory /var/www/html/MMServer/static>
Require all granted
</Directory>
WSGIDaemonProcess MMServer python-path=/var/www/html/MMServer python-home=/var/www/html/venv
WSGIProcessGroup MMServer
WSGIScriptAlias / /var/www/html/MMServer/mm_server/wsgi.py
<Directory /var/www/html/MMServer/mm_server>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
下面是我的 wsgi.py
文件:
import os
import sys
def application(environ, start_response):
start_response('200 OK',[('Content-type','text/html')])
return [sys.version]
只有一件事我可以通过这种方式获得(同时 WSGIDaemonProcess
和 WSGIProcessGroup
被删除)是:
2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]
编辑 1:
有可能我缺少软件包,因为我重新安装了 python 3.5,需要哪些软件包才能工作?
解决方案:
我做了两件事,我不确定是什么对我有帮助,但首先我禁用了 mod (a2dismod wsgi
) 并删除了一个包 libapache2-mod-wsgi
.
选项 1:
apt-get install libapache2-mod-wsgi-py3
选项 2:
我从源安装了一个mod-wsgi
:
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.3.tar.gz
tar -xf 4.6.3.tar.gz
./configure --with-python=/usr/local/bin/python3.6
make
make install
现在一切正常。
谢谢@Graham Dumpleton,你的回答很有帮助。
mod_wsgi 模块是链接到 Python 库的 C 代码。因此,它编译的 Python 版本嵌入在模块中。它不只是执行 python
程序。这意味着它必须针对您要使用的 Python 版本进行编译。您不能通过虚拟环境强制它使用不同的 Python 版本。关于在虚拟环境中使用 mod_wsgi 的文档中对此进行了说明。
简而言之,您需要卸载mod_wsgi模块(可能是操作系统打包的),并从源代码中自行安装mod_wsgi,针对Python版本进行编译你想用。最简单的方法是使用 pip install
方法。