2

I'm trying to deploy Django (located in a virtualenv) on Apache using WSGI deploying. I'm following the default tutorial from https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/

wsgi.py (the default one which Django generated, with the comments dropped):

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

apache2.conf (its the same httpd.conf just in Debian ). Appended this to the end:

WSGIScriptAlias / /home/user/Desktop/expofit/expofit_hg/py/server/server/wsgi.py
WSGIDaemonProcess example.com python-path=/home/user/Desktop/expofit/expofit_hg/py/server:/home/user/Desktop/expofit/expofit_env/lib/python2.7/site-packages
WSGIProcessGroup example.com

<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

Alias /static/ /home/user/Desktop/expofit/expofit_hg/py/server/server/static

<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server/static>
Order deny,allow
Allow from all
</Directory>

However, this ends with an error:

[Thu Dec 06 17:08:40 2012] [error] [client 192.168.56.1] ImportError: No module named django.core.wsgi

It seems that the standard python is accessible, since

import os

yields no errors. So it seems that modules imported from the virtualenv aren't importable. The tutorial said:

A further change required to the above configuration if you use daemon mode is that you can't use WSGIPythonPath; instead you should use the python-path option to WSGIDaemonProcess, for example:

WSGIDaemonProcess example.com python-path=/path/to/mysite.com:/path/to/venv/lib/python2.7/site-packages
WSGIProcessGroup example.com

What am I missing?

TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143

3 Answers3

2

The problem was in the permissions. I didn't check who was the user, and what the permissions were at the beginning, however, when I changed the permission 777 to all the directories containing Django code files, it started working.

I'm aware that a person has to be as careful as possible with permissions, and that giving 777 to everything isn't the best way to do it but should check how to make it work with minimum permission change. It however solves the problem in the question.

TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
1

For a single app this is the easiest to get out of the box, see http://code.google.com/p/modwsgi/wiki/VirtualEnvironments#Baseline_Environment Neither this or using WSGIPythonPath can be done for just a vhost but must be global.

WSGIPythonHome [path to virtualenv folder]

If you have multiple apps - using sys.path to append your virtualenv's site-packages folder at the top of wsgi.py seems the easiest thing to do, see http://code.google.com/p/modwsgi/wiki/VirtualEnvironments#Application_Environments.

Lincoln B
  • 2,184
  • 1
  • 13
  • 12
  • Did what U purposed and what the tutorial suggested. Ended up with an endless: "ImportError: No module named site" in Apache log. Change the code to what it was before, but the logs keep coming even dough there is no more "Import site" in wsgi.py – TheMeaningfulEngineer Dec 07 '12 at 07:42
  • Then you are using a mod_wsgi compiled against a different version of Python than the virtual environment is using, or you stuff up what you set WSGIPythonHome to. Because you are using daemon mode if using mod_wsgi 3.4, instead of WGSIPythonHome, use the python-home option to WSGIDaemonProcess directive. – Graham Dumpleton Dec 08 '12 at 01:53
  • @GrahamDumpleton but I dont see `python-home` option in `WSGIDaemonProcess` directive https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess – eldos Dec 11 '14 at 16:52
  • Go read http://blog.dscpl.com.au/2014/09/python-module-search-path-and-modwsgi.html The original docs are out of date. – Graham Dumpleton Dec 12 '14 at 05:41
1

the pythonpath your envinronment is different than the apache one i think.
install django "globaly" with easy_install or pip

or add .virtualenv pythonpath to the mod_wsgi config

WSGIPythonPath directory|directory-1:directory-2:

MOD_wsgi config

jxs
  • 457
  • 4
  • 9
  • 1
    I want to use wsgi in daemon mode, and it is specified in the Django documentation that in those cases "WSGIPythonPath" doesn't work, but has to be changed with "WSGIDaemonProcess example.com python-path=/path/to/mysite.com:/path/to/venv/lib/python2.7/site-packages" – TheMeaningfulEngineer Dec 07 '12 at 07:45