Question

I've just finished installing (or attempting to install) Django 1.6 on an EC2 server, but I seem to be having trouble with django.wsgi.

I've installed Django 1.6, httpd, and mod_wsgi, and I'm getting the "The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost..."

I get that I've made a misstep somewhere, but I can't seem to make out what the error logs are trying to tell me. I see there are some database errors near the bottom, and I haven't gotten to setting any up yet, but surely the errors above are from a different issue?

Here's is the latest from the error log:

[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] mod_wsgi (pid=1973): Exception occurred processing WSGI script '/home/ec2-user/Django-1.6/joshsite/apache/django.wsgi'.
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Traceback (most recent call last):
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     self.load_middleware()
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     mw_class = import_by_path(middleware_path)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     module = import_module(module_path)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     __import__(name)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     from django.contrib.auth.backends import RemoteUserBackend
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/backends.py", line 3, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     from django.contrib.auth.models import Permission
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     class Permission(models.Model):
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     new_class.add_to_class('_meta', Options(meta, **kwargs))
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     value.contribute_to_class(cls, name)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     return getattr(connections[DEFAULT_DB_ALIAS], item)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     backend = load_backend(db['ENGINE'])
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 131, in load_backend
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     raise ImproperlyConfigured(error_msg)
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] ImproperlyConfigured: 'mysql' isn't an available database backend.
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Try using 'django.db.backends.XXX', where XXX is one of:
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82]     u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
[Wed Apr 23 02:39:00 2014] [error] [client 75.75.80.82] Error was: No module named mysql.base
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] mod_wsgi (pid=1976): Exception occurred processing WSGI script '/home/ec2-user/Django-1.6/joshsite/apache/django.wsgi'.
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Traceback (most recent call last):
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     self.load_middleware()
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     mw_class = import_by_path(middleware_path)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     module = import_module(module_path)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     __import__(name)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     from django.contrib.auth.backends import RemoteUserBackend
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/backends.py", line 3, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     from django.contrib.auth.models import Permission
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     class Permission(models.Model):
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     new_class.add_to_class('_meta', Options(meta, **kwargs))
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     value.contribute_to_class(cls, name)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     return getattr(connections[DEFAULT_DB_ALIAS], item)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     backend = load_backend(db['ENGINE'])
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]   File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 131, in load_backend
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     raise ImproperlyConfigured(error_msg)
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] ImproperlyConfigured: 'mysql' isn't an available database backend.
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Try using 'django.db.backends.XXX', where XXX is one of:
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82]     u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
[Wed Apr 23 02:39:03 2014] [error] [client 75.75.80.82] Error was: No module named mysql.base

My django.wsgi is as follows:

import os,sys

apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('/home/ec2-user/Django-1.6/joshsite/joshsite')
sys.path.append('/home/ec2-user/Django-1.6/joshsite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'joshsite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

And I've added this in to the httpd.conf

<VirtualHost *:80>
    DocumentRoot /home/ec2-user/Django-1.6/joshsite
    ServerName ec2-54-187-46-240.us-west-2.compute.amazonaws.com
    ErrorLog /home/ec2-user/Django-1.6/joshsite/logs/apache_error.log
    CustomLog /home/ec2-user/Django-1.6/joshsite/logs/apache_access.log combined
    WSGIScriptAlias / /home/ec2-user/Django-1.6/apache/django.wsgi


    <Directory /home/ec2-user/Django-1.6/joshsite/media>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /home/ec2-user/Django-1.6/apache>
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    Alias /media/ /ec2-user/Django-1.6/joshsite/media/
</VirtualHost>

Here are the contents of settings.py:

"""
Django settings for joshsite project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ***

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'joshsite.urls'

WSGI_APPLICATION = 'joshsite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
       'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test',
        'USER': '**',
        'PASSWORD': '**',
        'HOST': '',
        'PORT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

Here is my urls.py:

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'joshsite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^home/', 'joshsite.views.home', name='home'),
)

Update: Sometimes at /, I get a 404 error:

Request Method: GET
Request URL:    http://ec2-54-187-46-240.us-west-2.compute.amazonaws.com/
Using the URLconf defined in joshsite.urls, Django tried these URL patterns, in this order:
^admin/
^home/ [name='home']
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Thank you in advance for any assistance.

But then after refreshing it sometimes goes back to a 500, almost as if chosen at random.

Was it helpful?

Solution

Check your DATABASE settings in settings.py. Looks like your ENGINE is bad. Try changing to:

'ENGINE': 'django.db.backends.mysql',

If this doesn't work, please post your database settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top