I have read similar questions/answers but I cant resolve the situation. So I have installed WSGI and want to serve my django app from Apache.
What I did initially was to create with virtualenv the folder testing which holds the python related stuff. So I did
virtualenv environment
My vhost file looks like:
<VirtualHost *:8001>
WSGIDaemonProcess myapp python-path=/var/www/vhosts/myapp.com/:/var/www/vhosts/myapp.com/environment/lib/python2.7/:/var/www/vhosts/myapp.com/environment/lib/python2.7/sites-available
WSGIScriptAlias / /var/www/vhosts/myapp/testing/wsgi.py
...
...
My wsgi.py is:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testing.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Once visiting the webpage I am getting a Server Internal Error and the error.log says 2 error messages basically:
[wsgi:error] [pid 31165] [client 192.168.0.3:31337] mod_wsgi (pid 31165): Target WSGI script '/var/www/vhosts/myapp.com/testing/wsgi.py' cannot be loaded as Python Module
and right after several lines that end to:
[wsgi:error] [pid 31165] [client 192.168.0.3:31337] mod_wsgi (pid 31165): ImportError: Could not import settings 'testing.settings' (is it on sys.path? Is there an import error in the settings file?)
I found regarding the first error msg this Target WSGI script cannot be loaded as Python module however I couldnt resolve the issue. What I get is that this error is not stopping Apache from trying to load my python (django) project since the next error is what I think causes the 500 response. For the second error I found that is a matter of adding the paths (something that I have done to my vhost file! ?)
I tried other solutions such as adding the WSGIPythonPath on my apache.conf but didnt work.
My wsgi.py file is as follows:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testing.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I also tried adding
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
sys.path.append('/var/www/vhosts/myapp/testing')
import mysite.settings
didnt work.