我正在努力为django运行apache2服务器。我想试试gunicorn,但是我希望apache可以更频繁地安装在工作场所,所以我会坚持下去。 问题目前(我认为)在apache error.log的摘录中可见的导入错误中。我已经尝试了很多可能的配置,并且在它甚至没有导入django之前。我正在使用虚拟环境。来自django的开发人员服务器对于应用程序和数据库都可以正常工作。
1 [Sun Apr 02 20:58:52.082706 2017] [wsgi:warn] [pid 13495] mod_wsgi: Compiled for Python/3.4.2rc1+.
2 [Sun Apr 02 20:58:52.082907 2017] [wsgi:warn] [pid 13495] mod_wsgi: Runtime using Python/3.4.2.
3 [Sun Apr 02 20:58:52.104626 2017] [mpm_prefork:notice] [pid 13495] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/3.4.2 configu red -- resuming normal operations
4 [Sun Apr 02 20:58:52.104798 2017] [core:notice] [pid 13495] AH00094: Command line: '/usr/sbin/apache2'
5 [Sun Apr 02 21:00:18.727276 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] mod_wsgi (pid=13499): Target WSGI script '/home/pi/d jangoProjects/pidjay/pidjay/wsgi.py' cannot be loaded as Python module.
6 [Sun Apr 02 21:00:18.727660 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] mod_wsgi (pid=13499): Exception occurred processing WSGI script '/home/pi/djangoProjects/pidjay/pidjay/wsgi.py'.
7 [Sun Apr 02 21:00:18.727938 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] Traceback (most recent call last):
8 [Sun Apr 02 21:00:18.729807 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] File "/home/pi/djangoProjects/pidjay/venv/lib/pyth on3.5/site-packages/django/db/backends/mysql/base.py", line 25, in <module>
9 [Sun Apr 02 21:00:18.729866 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] import MySQLdb as Database
10 [Sun Apr 02 21:00:18.730794 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] File "/home/pi/djangoProjects/pidjay/venv/lib/pyth on3.5/site-packages/MySQLdb/__init__.py", line 19, in <module>
11 [Sun Apr 02 21:00:18.730848 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] import _mysql
12 [Sun Apr 02 21:00:18.731024 2017] [wsgi:error] [pid 13499] [remote 192.168.1.106:0] ImportError: No module named '_mysql'
现在来自sites-available文件夹的配置:
<Directory /home/pi/djangoProjects/pidjay/pidjay>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess pidjay python-path=/home/pi/djangoProjects/pidjay:/home/pi/djangoProjects/pidjay/venv/lib/python3.5/site-packages
WSGIProcessGroup pidjay
WSGIScriptAlias / /home/pi/djangoProjects/pidjay/pidjay/wsgi.py
正如您所看到的,我使用冒号指定了虚拟env文件夹,其他方式导致django无法导入。环境中的python是ver 3.5(检查两次),安装了sqlclient和django。当我尝试导入&#34; _mysql&#34;在venv内部的python解释器中(激活)它工作正常。
这是来自project&settings;设置的数据库设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': "pidjay",
"USER": "user",
"PASSWORD": "password"
}}
正如我所说,它适用于开发服务器。请帮帮我,非常感谢你提前!我很乐意提供任何其他信息!
答案 0 :(得分:0)
格雷厄姆亲切地指出,问题在于版本不匹配。在官方文档的帮助下编译mod_wsgi for python 3.5并将其加载到apache后,它按预期工作。
答案 1 :(得分:0)
如上所述,这是一种方法。
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.14.tar.gz
tar -zxvf 4.5.14.tar.gz
cd mod_wsgi-4.5.14
./configure --with-python=/usr/bin/python3.5
make
make install
chmod 755 /usr/lib64/httpd/modules/mod_wsgi.so