I am trying to publish my site on an Amazon\'s EC2 Instance, and I keep getting a 500 error. I really dunno why.
//Log Files
[Sun Feb 17 23:12:48
You've configured everything very well my friend, just need to give the apache user permission to access both project and virtualenv dirs.
Example:
sudo chown -R www-data:www-data /home/ubuntu/projects
sudo chown -R www-data:www-data /home/ubuntu/virtualenv
This solved my problem with ImportError: No module named django.core.wsgi
(virtualenvs folders) and ImportError: No module named <project-name>.settings
(projects folders)
For me, this indicated Django wasn't installed on the sever. Fixed via
pip install Django
For me it was some variables that needed to be setted (for windows) :
set PYTHONHOME=F:\path\to\python
set PYTHONPATH=F:\path\to\python
I know that this is an old thread but I've just bumped into the same issue and I don't think that this is caused by a missing package. As the Django core distribution contains the correct wsgi handler already.
The problem here is that when wsgi.py is executed it's missing the packages of the site-packages from your virtualenv. (If you have activated your virtualenv, and done pip install django then everything is fine. You have the necessary django packages).
As far as I'm concerned, I fixed the issue modifying the sys.path in my Path/to/Project/Project/wsgi.py file.
You have to append your project dir and your virtualenv site-packages to the sys.path List. Here is my wsgi.py file contained in my project (Talking about the wsgi.py created with django-admin.py start-project)... that I had to modify in order to make it work with Apache
# =====================
# wsgi.py file begin
import os, sys
# add the hellodjango project path into the sys.path
sys.path.append('<PATH_TO_MY_DJANGO_PROJECT>/hellodjango')
# add the virtualenv site-packages path to the sys.path
sys.path.append('<PATH_TO_VIRTUALENV>/Lib/site-packages')
# poiting to the project settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodjango.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# wsgi.py file end
# ===================
Make sure:
you added mod_wsgi to the Apache modules dir mod_wsgi must be compiled for the OS, Apache and Python version you have
added the load module command into your httpd.conf to load mod_wsgi module LoadModule wsgi_module modules/mod_wsgi.so
configured Django specifics in your httpd.conf or any conf you include in your httpd.conf
Based on the documentation How to use Django with Apache and mod_wsgi
WSGIScriptAlias / <PATH_TO_PROJECT>/hellodjango/hellodjango/wsgi.py
WSGIPythonPath <PATH_TO_PROJECT>:<PATH_TO_VIRTUALENV>/Lib/site-packages
<Directory <PATH_TO_PROJECT>/hellodjango/hellodjango>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
Hope this helps. It worked for me.