I'm running a CentOS 7 server and I managed to get a Django site up and running by doing the following:
- Ran
yum install httpd gcc mod_wsgi
- Installed PostgreSQL 9.4
- Downloaded and compiled Python 3.4
- Used pyvenv3.4 to create a virtual environment
- Ran
pip install django django-extensions psycopg2
in the virtual environment - Started a new Django project
mysite
in the virtual environment - And finally configured Apache2 and PostgreSQL 9.4
The previous steps successfully installed a new Django 1.8 project and I was able to view the It worked!
page in my browser.
The problems start when I modify the settings.py
file to use PostgreSQL 9.4 as my project's database. I change the default DATABASES
dictionary to the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
When I press refresh in my browser, I then get an Internal Server Error
from Apache and the error_log says:
[] mod_wsgi (pid=1049): Target WSGI script '/var/www/django/projects/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[] mod_wsgi (pid=1049): Exception occurred processing WSGI script '/var/www/django/projects/mysite/mysite/wsgi.py'.
[] Traceback (most recent call last):
[] File "/var/www/django/projects/mysite/mysite/wsgi.py", line 16, in <module>
[] application = get_wsgi_application()
[] File "/var/www/django/virtual_environments/mysite/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[] django.setup()
[] File "/var/www/django/virtual_environments/mysite/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
[] apps.populate(settings.INSTALLED_APPS)
[] File "/var/www/django/virtual_environments/mysite/lib/python3.4/site-packages/django/apps/registry.py", line 78, in populate
[] raise RuntimeError("populate() isn't reentrant")
[] RuntimeError: populate() isn't reentrant
[] mod_wsgi (pid=1049): Target WSGI script '/var/www/django/projects/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[] mod_wsgi (pid=1049): Exception occurred processing WSGI script '/var/www/django/projects/mysite/mysite/wsgi.py'.
[] Traceback (most recent call last):
[] File "/var/www/django/projects/mysite/mysite/wsgi.py", line 16, in <module>
[] application = get_wsgi_application()
[] File "/var/www/django/virtual_environments/mysite/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[] django.setup()
[] File "/var/www/django/virtual_environments/mysite/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
[] apps.populate(settings.INSTALLED_APPS)
[] File "/var/www/django/virtual_environments/mysite/lib/python3.4/site-packages/django/apps/registry.py", line 78, in populate
[] raise RuntimeError("populate() isn't reentrant")
[] RuntimeError: populate() isn't reentrant
I've tried everything I can think of to resolve it. I think the problem is specific to the use of Python 3.4 and maybe not having the correct version of mod_wsgi to work with it.
I've tried installing mod_wsgi via pip but I'm not sure how to get Apache to use that version and not the system wide version. That may not even be what's causing the problem.
I've tried nearly every Q&A on this site with no luck so any help will be appreciated,
Thanks.
EDIT
Here's my VirtualHost
configuration for Apache2:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
DocumentRoot /var/www/django/projects/mysite/mysite
WSGIScriptAlias / /var/www/django/projects/mysite/mysite/wsgi.py
WSGIDaemonProcess example.com python-path=/var/www/django/projects/mysite:/var/www/django/virtual_environments/mysite/lib/python3.4/site-packages
WSGIProcessGroup example.com
<Directory /var/www/django/projects/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>