I've been struggling to deploy
Django application on Amazon EC2 using Bitnami Djangostack for the last couple of days. When I go to http://dewey.io I see the default bitnami page (/opt/bitnami/apache2/htdocs/index.html), however, when I open http://dewey.io/portnoy, I get 'Internal Server Error'. But it's known that if mod_wsgi is setup correctly, the DocumentRoot value from httpd.conf is ignored, thus, I should see my
Django application when accessing http://dewey.io. Essentially, the main error is this - 'Target WSGI script cannot be loaded as Python module'. Two questions: 1) any ideas how to fix these mod_wsgi errors (the Apache logs are below)? 2) how to disable the default /opt/bitnami/apache2/htdocs/index.html page and show my homepage from
django application when accessing http://dewey.io? Thank you in advance!
The details
On my EC2 instance I"m running 64-bit Ubuntu 12.04 with DjangoStack 1.4-1. My
Django project is located here - /opt/bitnami/apps/django/django_projects/portnoy.
root@dewey:/opt/bitnami/apps/django/django_projects/portnoy# ls
manage.py README.md settings.py site_media users Procfile sandbox static test.py topics urls.py views.py __init__.pyc templates testviews.py
Apache error logs (/opt/bitnami/apache2/logs/error_log):
[Wed Jul 04 02:29:00 2012] [error] [client 140.180.6.212] File does not exist: /opt/bitnami/apache2/htdocs/favicon.ico
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] mod_wsgi (pid=3990): Target WSGI script '/opt/bitnami/apps/django/scripts/django.wsgi' cannot be loaded as Python module.
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] mod_wsgi (pid=3990): Exception occurred processing WSGI script '/opt/bitnami/apps/django/scripts/django.wsgi'.
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] Traceback (most recent call last):
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File "/opt/bitnami/apps/django/scripts/django.wsgi", line 8, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] import
django.core.handlers.wsgi
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 8, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] from
django import http
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/http/__init__.py", line 119, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] from
django.http.multipartparser import MultiPartParser
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/http/multipartparser.py", line 13, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] from
django.utils.text import unescape_entities
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/utils/text.py", line 4, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] from gzip import GzipFile
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File "/opt/bitnami/python/lib/python2.7/gzip.py", line 10, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] import io
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File "/opt/bitnami/python/lib/python2.7/io.py", line 60, in <module>
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] import _io
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] ImportError: /opt/bitnami/python/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
[Wed Jul 04 02:29:15 2012] [error] [client 140.180.6.212] File does not exist: /opt/bitnami/apache2/htdocs/favicon.ico
[Wed Jul 04 02:44:00 2012] [error] [client 140.180.6.212] File does not exist: /opt/bitnami/apache2/htdocs/favicon.ico
Let me quickly introduce the contents of the files to make the case more concrete.
This is my /etc/apache2/sites-available/default file
<VirtualHost *:80>
ServerAdmin
[email protected]
ServerName dewey.io
Alias /site_media/ /opt/bitnami/apps/django/django_projects/portnoy/site_media/
Alias /static/ /opt/bitnami/apps/django/lib/python2.7/site-packages/django/contrib/admin/static/
Alias /robots.txt /opt/bitnami/apps/django/django_projects/portnoy/site_media/robots.txt
Alias /favicon.ico /opt/bitnami/apps/django/django_projects/portnoy/site_media/favicon.ico
CustomLog "|/usr/sbin/rotatelogs /opt/bitnami/apps/django/django_projects/logs/access.log.%Y%m%d-%H%M%S 5M" combined
ErrorLog "|/usr/sbin/rotatelogs /opt/bitnami/apps/django/django_projects/logs/error.log.%Y%m%d-%H%M%S 5M"
LogLevel warn
WSGIProcessGroup dewey.io
WSGIScriptAlias / /opt/bitnami/apps/django/scripts/django.wsgi
<Directory /opt/bitnami/apps/django/django_projects/portnoy/site_media>
Order deny,allow
Allow from all
Options -Indexes FollowSymLinks
</Directory>
<Directory /opt/bitnami/apps/django/django_projects/portnoy/conf/apache>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
This is my /opt/bitnami/apps/django/scripts/django.wsgi file
import os, sys
sys.path.append('/opt/bitnami/apps/django/lib/python2.7/site-packages/')
sys.path.append('/opt/bitnami/apps/django/django_projects')
sys.path.append('/opt/bitnami/apps/django/django_projects/portnoy')
os.environ['DJANGO_SETTINGS_MODULE'] = 'portnoy.settings'
import
django.core.handlers.wsgi
application =
django.core.handlers.wsgi.WSGIHandler()
Here is the relevant portion of /opt/bitnami/apache2/conf/httpd.conf file:
ServerRoot "/opt/bitnami/apache2"
Listen 80
ServerName dewey.io
DocumentRoot "/opt/bitnami/apache2/htdocs"
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/bitnami/python
Include "/opt/bitnami/apache2/conf/ssi.conf"
Include "/opt/bitnami/apps/django/conf/django.conf"
Include "/opt/bitnami/apache2/conf/bitnami/httpd.conf"