I'm getting 500 error while trying to start Django (1.10.5) on Apache (with mod_wsgi) using postgre DB. The installation dependencies are django and. psycopg2. They are installed on a Python 3.6 virtual environment.
Hint: Everything works fine, when I try to start the virtual environment via "python manage.py runserver 0.0.0.0:8000" but when I try to reach the :80 port on apache the following error is listed in /var/log/httpd/error_log
Handling WSGI exception
Traceback (most recent call last):
File "/root/djangotest/djangotest/wsgi.py", line 40, in <module> application = get_wsgi_application()
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application django.setup(set_prefix=False)
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS)
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models(all_models)
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/apps/config.py", line 199, in import_models self.models_module = import_module(models_module_name)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module __import__(name)
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/contrib/auth/models.py", line 4, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 52, in <module> class AbstractBaseUser(models.Model):
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/db/models/base.py", line 119, in __new__ new_class.add_to_class('_meta', Options(meta, app_label))
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/db/models/base.py", line 316, in add_to_class value.contribute_to_class(cls, name)
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/db/models/options.py", line 214, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/db/utils.py", line 211, in __getitem__ backend = load_backend(db['ENGINE'])
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/db/utils.py", line 115, in load_backend return import_module('%s.base' % backend_name)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module __import__(name)
File "/root/djangotest/djangotestvenv/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 24, in <module> raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
ImproperlyConfigured: Error loading psycopg2 module: No module named _psycopg [remote 88.AAA.BBB.CC:76] mod_wsgi (pid=18487): Target WSGI script '/root/djangotest/djangotest/wsgi.py' does not contain WSGI application 'application'.
The content of /etc/httpd/conf.d/django.conf :
Alias /static /root/djangotest/static
WSGIScriptAlias / /root/djangotest/djangotest/wsgi.py
WSGIPythonPath /root/djangotest:/root/djangotest/djangotestvenv/lib/python3.6/site-packages
<Directory /root/djangotest/static>
Require all granted
</Directory>
<Directory /root/djangotest/djangotest>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess djangotest python-path=/root/djangotest:/root/djangotest/djangotestvenv/lib/python3.6/site-packages
WSGIProcessGroup djangotest
The content of wsgi.py :
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangotest.settings'
try:
application = get_wsgi_application()
print("WSGI without exception")
except Exception:
print("handling WSGI exception")
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
Although the psycopg2 is installed on venv succesfully and works fine, it throws error when trying to reach: 80 via with apache & mod_wsgi.
Thank you.