I'm writing a django site for internal use in my organization. I'm using the test-driven approach to developing the site set out in this tutorial because I think that's good practice. I'm using Ubuntu 12.04, and the apache server and mod_wsgi from the repositories. My development is taking place in a virtualenv created using virtualenvwrapper.
I want to test the site in conditions as close to what will be the production server as possible, so I'm trying to configure a local apache server on my laptop using mod_wsgi, which I've never done before. I've read the relevant bits of the mod_wsgi and django docs and watched this video, which solved the problems I was having with file permissions. But I seem to be stuck at a final hurdle that presentation doesn't address - I presume because I'm using django 1.4 and it relates to an earlier version but I'm not sure. I'm committed to using a local apache server rather than the django development server because the site needs search, which I want to get through haystack and apache solr, and I want to test it and resolve any problems before I deploy.
My wsgi.py file is just the stock django one. After trimming the docstring it looks like this:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fugit.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
My httpd.conf looks like this:
WSGIScriptAlias / /var/www/djcode/fugit/fugit/fugit/apache/wsgi.py
WSGIPythonPath /var/www/djcode/fugit/fugit/fugit:/home/garry/.virtualenvs/fugit/lib/python2.7/site-packages
<Directory /var/www/djcode/fugit/fugit/fugit>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
When I visit localhost I get the following error. It looks like a PYTHONPATH problem, but my understanding of the django documentation was that line two in the httpd.conf above should have resolved that.
[Fri Dec 28 10:22:03 2012] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Fri Dec 28 10:22:03 2012] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Fri Dec 28 10:22:03 2012] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3280): Target WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py' cannot be loaded as Python module.
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3280): Exception occurred processing WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py'.
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] File "/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py", line 23, in <module>
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] from django.core.wsgi import get_wsgi_application
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.wsgi
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3279): Target WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py' cannot be loaded as Python module.
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3279): Exception occurred processing WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py'.
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] File "/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py", line 23, in <module>
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] from django.core.wsgi import get_wsgi_application
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.wsgi
Can anyone tell me what I'm missing here?
EDIT:
It looks like I might have a virtualenvwrapper permissions problem. I've tried moving my virtualenvs as suggested by this answer but now virtualenvwrapper can't seem to find itself. I'm getting `[Errno 13] Permission denied' on trying to load initialization hooks. I've chmod 755 the new directory but no dice.
FURTHER EDIT: I have side-stepped this issue by using nginx as a reverse proxy for gunicorn instead of deploying with Apache. It was set up and running smoothly in about half an hour.