问题
I'm making a website based on Django, on the server was installed a Python 3.5, but my project requires a Python 3.6. I decided to use virtualenv. I successfuly installed needed version of Python but I can't make it works with Apatche2 using virtualenv
.
Website is able to run only on Python 2.7, otherwise nothing happens, page is loading for a long time without any error.
Here is my VirtualHost config with my try to run on 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>
Below is my wsgi.py
file:
import os
import sys
def application(environ, start_response):
start_response('200 OK',[('Content-type','text/html')])
return [sys.version]
Only one thing what I can get this way (while WSGIDaemonProcess
and WSGIProcessGroup
is deleted) is:
2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]
Edit 1:
There is a posiblity I have missing packages, bacause I made reinstalation of python 3.5, what are required packages to work?
Solution:
I did two things, I'm not sure what exacly help me but first of all I disabled a mod (a2dismod wsgi
) and deleted a package libapache2-mod-wsgi
.
Option 1:
apt-get install libapache2-mod-wsgi-py3
Option 2:
I installed a mod-wsgi
from the source: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
Now everything works perfectly.
Thanks @Graham Dumpleton, your answer was helpful.
回答1:
The mod_wsgi module is C code which links to the Python library. Thus the version of Python it is compiled for is embedded in the module. It doesn't just execute python
program. This means it has to be compiled for the version of Python you want to use. You cannot force it via a virtual environment to use a different Python version. This is stated in the documentation on using mod_wsgi with virtual environments.
- http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
In short, you need to uninstall the mod_wsgi module (likely the operating system packaged one), and install mod_wsgi yourself from source code, compiling it against the Python version you want to use. Easiest way of doing that is to use pip install
method.
- https://pypi.python.org/pypi/mod_wsgi
来源:https://stackoverflow.com/questions/49495403/cant-run-apache2-with-virtualenv