I have a Django site and a Django CMS site which I am serving from the same ubuntu 14.04 server running MySQL 5.6, Apache2 2.4.7 and Django 1.8 via mod_wsgi version 4.5.7 using virtual hosts. Locally (on my Linux PC) I have managed to accomplish this with both sites working perfectly and hence decided to migrate to the server.
After the migration, taking care that everything has the same version, the situation is such that the Django site is working properly while the Django CMS site is giving me and internal server error 500. These are my virtual hosts' .conf files, and the wsgi.py file for the broken site.
# wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bsg.settings")
application = get_wsgi_application()
# Django_cms_site.conf
<VirtualHost *:80>
ServerName site.com
ServerAdmin webmaster@localhost.com
Alias /static/ /home/bsg/cms/static/
Alias /media/ /home/bsg/cms/media/
WSGIScriptAlias / /home/bsg/cms/bsg/wsgi.py
WSGIDaemonProcess bsgcms python-path=/home/hicklin/bsg/cms:/home/venv-bsg/lib/python2.7/site-packages
WSGIProcessGroup bsgcms
<Directory /home/bsg/cms>
Require all granted
</Directory>
LogLevel warn
ErrorLog /var/log/apache2/cms-error.log
CustomLog /var/log/apache2/cms-access.log combined
</VirtualHost>
# Django_site.conf
<VirtualHost *:80>
ServerName django.site.com
ServerAdmin webmaster@localhost.com
Alias /static/ /home/bsg/admin/site/static/
WSGIScriptAlias / /home/bsg/admin/site/wsgi.py
WSGIDaemonProcess bsgadmin python-path=/home/bsg/admin:/home/hicklin/venv-bsg/lib/python2.7/site-packages
WSGIProcessGroup bsgadmin
<Directory /home/bsg/admin>
Require all granted
</Directory>
LogLevel warn
ErrorLog /var/log/apache2/admin-error.log
CustomLog /var/log/apache2/admin-access.log combined
</VirtualHost>
As can be noted, I am using the same virtual environment for both sites. The relevant logs give the following error.
[Tue Oct 11 22:39:43.416901 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] mod_wsgi (pid=19799): Target WSGI script '/home/bsg/cms/bsg/wsgi.py' cannot be loaded as Python module.
[Tue Oct 11 22:39:43.416942 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] mod_wsgi (pid=19799): Exception occurred processing WSGI script '/home/bsg/cms/bsg/wsgi.py'.
[Tue Oct 11 22:39:43.416977 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] Traceback (most recent call last):
[Tue Oct 11 22:39:43.417014 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] File "/home/bsg/cms/bsg/wsgi.py", line 16, in <module>
[Tue Oct 11 22:39:43.417067 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] application = get_wsgi_application()
[Tue Oct 11 22:39:43.417093 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] File "/home/venv-bsg/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Tue Oct 11 22:39:43.417134 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] django.setup()
[Tue Oct 11 22:39:43.417158 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] File "/home/venv-bsg/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Tue Oct 11 22:39:43.417194 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] apps.populate(settings.INSTALLED_APPS)
[Tue Oct 11 22:39:43.417217 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] File "/home/venv-bsg/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
[Tue Oct 11 22:39:43.417255 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] raise RuntimeError("populate() isn't reentrant")
[Tue Oct 11 22:39:43.417289 2016] [wsgi:error] [pid 19799] [remote 77.71.226.73:64984] RuntimeError: populate() isn't reentrant
After modifying the wsgi.py to get the real error as suggested by Dirk Eschler in the thread, the error in /var/log/apache2/cms-error.log changes to
[Tue Oct 11 21:36:06.087723 2016] [wsgi:error] [pid 21584] handling WSGI exception
[Tue Oct 11 21:36:06.087811 2016] [wsgi:error] [pid 21584] Traceback (most recent call last):
[Tue Oct 11 21:36:06.087854 2016] [wsgi:error] [pid 21584] File "/home/bsg/cms/bsg/wsgi.py", line 9, in <module>
[Tue Oct 11 21:36:06.087975 2016] [wsgi:error] [pid 21584] application = get_wsgi_application()
[Tue Oct 11 21:36:06.087996 2016] [wsgi:error] [pid 21584] File "/home/venv-bsg/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Tue Oct 11 21:36:06.088067 2016] [wsgi:error] [pid 21584] django.setup()
[Tue Oct 11 21:36:06.088093 2016] [wsgi:error] [pid 21584] File "/home/venv-bsg/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
[Tue Oct 11 21:36:06.088164 2016] [wsgi:error] [pid 21584] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Oct 11 21:36:06.088190 2016] [wsgi:error] [pid 21584] File "/home/venv-bsg/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
[Tue Oct 11 21:36:06.088366 2016] [wsgi:error] [pid 21584] self._setup(name)
[Tue Oct 11 21:36:06.088388 2016] [wsgi:error] [pid 21584] File "/home/venv-bsg/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
[Tue Oct 11 21:36:06.088417 2016] [wsgi:error] [pid 21584] % (desc, ENVIRONMENT_VARIABLE))
[Tue Oct 11 21:36:06.088442 2016] [wsgi:error] [pid 21584] ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
[Tue Oct 11 21:36:08.591950 2016] [wsgi:error] [pid 21584] [remote 77.71.226.73:3851] mod_wsgi (pid=21584): Target WSGI script '/home/bsg/cms/bsg/wsgi.py' does not contain WSGI application 'application'.
Please note that I have managed to run, access and work the cms site via python manage.py runserver and it works without a hitch. Following the latest error did not result in anything fruitful yet. Any help or hints are greatly appreciated.