Déploiement de django dans un virtualenv avec l’aide du mode démon apache / mod_wsgi

J’ai passé beaucoup de temps à googler et à lire la documentation et les réponses au stackoverflow, mais je ne pouvais pas déployer django dans un virtualenv avec l’aide du mode démon apache / mod_wsgi.

Voici mon fichier de config apache:

 ServerAdmin [email protected] ServerName example.com LogLevel info WSGIDaemonProcess example.com python-path=/var/www/testproject:/root/.virtualenvs/env1/lib/python2.7/site-packages WSGIProcessGroup example.com WSGIScriptAlias / /var/www/testproject/testproject/wsgi.py   Order deny,allow Allow from all   ErrorLog /var/www/testproject/log/error.log CustomLog /var/www/testproject/log/access.log combined  

Ceci est mon fichier wsgi.py (Je ne l’ai pas touché):

 import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() 

Voici mon fichier journal:

 [Thu Jan 22 18:45:12.289458 2015] [:info] [pid 585:tid 139777547847552] mod_wsgi (pid=585): Cleanup interpreter ''. [Thu Jan 22 18:45:12.293845 2015] [:info] [pid 585:tid 139777547847552] mod_wsgi (pid=585): Terminating Python. [Thu Jan 22 18:45:12.296594 2015] [:info] [pid 585:tid 139777547847552] mod_wsgi (pid=585): Python has shutdown. [Thu Jan 22 18:45:13.364017 2015] [:info] [pid 982:tid 139775604578176] mod_wsgi (pid=982): Attach interpreter ''. [Thu Jan 22 18:45:13.365960 2015] [:info] [pid 982:tid 139775604578176] mod_wsgi (pid=982): Adding '/var/www/testproject' to path. [Thu Jan 22 18:45:13.366464 2015] [:info] [pid 982:tid 139775604578176] mod_wsgi (pid=982): Adding '/root/.virtualenvs/env1/lib/python2.7/site-packages' to path. [Thu Jan 22 18:45:35.255450 2015] [:info] [pid 982:tid 139775484114688] mod_wsgi (pid=982): Create interpreter 'example.com|'. [Thu Jan 22 18:45:35.257781 2015] [:info] [pid 982:tid 139775484114688] mod_wsgi (pid=982): Adding '/var/www/testproject' to path. [Thu Jan 22 18:45:35.258663 2015] [:info] [pid 982:tid 139775484114688] mod_wsgi (pid=982): Adding '/root/.virtualenvs/env1/lib/python2.7/site-packages' to path. [Thu Jan 22 18:45:35.259379 2015] [:info] [pid 982:tid 139775484114688] [remote 206.190.152.176:8971] mod_wsgi (pid=982, process='env1', application='example.com|'): Loading WSGI script '/var/www/testproject/testproject/wsgi.py'. [Thu Jan 22 18:45:35.259995 2015] [:error] [pid 982:tid 139775484114688] [remote 206.190.152.176:8971] mod_wsgi (pid=982): Target WSGI script '/var/www/testproject/testproject/wsgi.py' cannot be loaded as Python module. [Thu Jan 22 18:45:35.260417 2015] [:error] [pid 982:tid 139775484114688] [remote 206.190.152.176:8971] mod_wsgi (pid=982): Exception occurred processing WSGI script '/var/www/testproject/testproject/wsgi.py'. [Thu Jan 22 18:45:35.260669 2015] [:error] [pid 982:tid 139775484114688] [remote 206.190.152.176:8971] Traceback (most recent call last): [Thu Jan 22 18:45:35.260888 2015] [:error] [pid 982:tid 139775484114688] [remote 206.190.152.176:8971] File "/var/www/testproject/testproject/wsgi.py", line 13, in  [Thu Jan 22 18:45:35.261212 2015] [:error] [pid 982:tid 139775484114688] [remote 206.190.152.176:8971] from django.core.wsgi import get_wsgi_application [Thu Jan 22 18:45:35.261463 2015] [:error] [pid 982:tid 139775484114688] [remote 206.190.152.176:8971] ImportError: No module named django.core.wsgi [Thu Jan 22 18:45:35.693482 2015] [:info] [pid 982:tid 139775500916480] [remote 206.190.152.176:37373] mod_wsgi (pid=982, process='env1', application='example.com|'): Loading WSGI script '/var/www/testproject/testproject/wsgi.py'. [Thu Jan 22 18:45:35.694122 2015] [:error] [pid 982:tid 139775500916480] [remote 206.190.152.176:37373] mod_wsgi (pid=982): Target WSGI script '/var/www/testproject/testproject/wsgi.py' cannot be loaded as Python module. [Thu Jan 22 18:45:35.694140 2015] [:error] [pid 982:tid 139775500916480] [remote 206.190.152.176:37373] mod_wsgi (pid=982): Exception occurred processing WSGI script '/var/www/testproject/testproject/wsgi.py'. [Thu Jan 22 18:45:35.694180 2015] [:error] [pid 982:tid 139775500916480] [remote 206.190.152.176:37373] Traceback (most recent call last): [Thu Jan 22 18:45:35.694220 2015] [:error] [pid 982:tid 139775500916480] [remote 206.190.152.176:37373] File "/var/www/testproject/testproject/wsgi.py", line 13, in  [Thu Jan 22 18:45:35.694267 2015] [:error] [pid 982:tid 139775500916480] [remote 206.190.152.176:37373] from django.core.wsgi import get_wsgi_application [Thu Jan 22 18:45:35.694296 2015] [:error] [pid 982:tid 139775500916480] [remote 206.190.152.176:37373] ImportError: No module named django.core.wsgi 

example.com est mon nom de domaine et env1 est le nom de mon virtualenv

Dans mon fichier journal, je peux voir que virtualenv a été ajouté au chemin:

 '/root/.virtualenvs/env1/lib/python2.7/site-packages' to path. 

Mais je reçois toujours une erreur:

 ImportError: No module named django.core.wsgi 

Installer django globalement résout le problème, mais ce n’est pas ce que je veux.

Je suis sur Ubuntu 12.10 , Django 1.7 , Python 2.7

les références:

  1. https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode
  2. https://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide#Delegation_To_Daemon_Process
  3. http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html