Setting up django on xampp with apache, python 2.6 and mod_wsgi

391 views
Skip to first unread message

Michael Ralan

unread,
Jul 31, 2009, 8:36:40 AM7/31/09
to Django users
Hi,

I've searched the internet and come across a couple of pages
ostensibly showing how this is done, but even the django documentation
itself (sans being xampp-specific) has not met me with success.

I got to the point where I've installed mod_wsgi, set up the test app
but am struggling with the changes I need to make to http.conf. I've
done them but when I request a page, httpd.exe throws an error
complaining about it trying to load a library incorrectly. If I take
remove the bit I added to http.conf apache will work.

This is what I've added to my http.conf where testproject is the name
of my app.

#django specific stuff
<VirtualHost *:8080>
ServerAdmin ro...@mysite.com
ServerName localhost
ServerAlias localhost.com
<Directory c:/xampp/htdocs/testproject/apache>
Allow from all
</Directory>
#WSGIDaemonProcess www-data
#WSGIProcessGroup www-data
WSGIScriptAlias / c:/xampp/htdocs/testproject/apache/django.wsgi
</VirtualHost>

This is the contents of my django.wsgi

import os, sys
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
sys.path.append('c:/xampp/htdocs')
os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()


The mod_wsgi I'm using I downloaded from
http://code.google.com/p/modwsgi/downloads/list

I don't see anything wrong?

Any helpful comments will be much appreciated,

Thanks

Karen Tracey

unread,
Jul 31, 2009, 8:48:40 AM7/31/09
to django...@googlegroups.com
On Fri, Jul 31, 2009 at 8:36 AM, Michael Ralan <mr5...@gmail.com> wrote:

Hi,

I've searched the internet and come across a couple of pages
ostensibly showing how this is done, but even the django documentation
itself (sans being xampp-specific) has not met me with success.

I got to the point where I've installed mod_wsgi, set up the test app
but am struggling with the changes I need to make to http.conf. I've
done them but when I request a page, httpd.exe throws an error
complaining about it trying to load a library incorrectly.

Details of this error may help people help you.  Trying to spot what might be wrong in the absence of the specifics of the error that gets reported is making things needlessly hard on potential helpers.

Karen

Michael Ralan

unread,
Jul 31, 2009, 8:53:04 AM7/31/09
to Django users

I get an (unhelpful) xampp error message that reads


Microsoft Visual C++ Runtime Library
---------------------------
Runtime Error!

Program: C:\xampp\apache\bin\httpd.exe

R6034

An application has made an attempt to load the C runtime library
incorrectly.
Please contact the application's support team for more information.

Furthermore, the following is in my apache errors.log

[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] mod_wsgi
(pid=2136): Target WSGI script 'C:/xampp/htdocs/testproject/apache/
django.wsgi' cannot be loaded as Python module.
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] mod_wsgi
(pid=2136): Exception occurred processing WSGI script 'C:/xampp/htdocs/
testproject/apache/django.wsgi'.
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] Traceback (most
recent call last):
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] File "C:/xampp/
htdocs/testproject/apache/django.wsgi", line 6, in <module>
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] import
django.core.handlers.wsgi
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] File "C:\
\Python26\\Lib\\site-packages\\django\\core\\handlers\\wsgi.py", line
8, in <module>
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] from django
import http
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] File "C:\
\Python26\\Lib\\site-packages\\django\\http\\__init__.py", line 5, in
<module>
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] from urllib
import urlencode
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] File "C:\
\Python26\\lib\\urllib.py", line 26, in <module>
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] import
socket
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] File "C:\
\Python26\\lib\\socket.py", line 46, in <module>
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] import
_socket
[Fri Jul 31 12:04:18 2009] [error] [client 127.0.0.1] ImportError: DLL
load failed: A dynamic link library (DLL) initialization routine
failed.

Karen Tracey

unread,
Jul 31, 2009, 9:23:08 AM7/31/09
to django...@googlegroups.com

All of which implies to me there's nothing wrong with your definitions, but there is something fundamentally broken with the server setup.  From the traceback you can see mod_wsgi itself is getting loaded fine, the django code is being found, etc.  Where things go south is when Python tries to load a C extension ("import _socket").  If Python can't load C extensions there's not much Python code that is going to work on this server.

You don't see an error when you remove your changes to http.conf because then you're probably not trying to use Python code at all from this server.  That doesn't mean there's anything wrong with the changes you made, it just means they are exposing an underlying problem you had not run across before because it is in code you were not attempting to use.

For some reason Python on this server cannot load C extensions, that's the problem you need to fix.  I'd Google around for Python, xampp, C extensions, that unhelpful error message, etc. and see if there is some trick to getting Python to work correctly in this environment.  Until you've got a server that can actually run Python properly you've no chance of getting Django to work on top of it.

Karen

Michael Ralan

unread,
Jul 31, 2009, 9:32:03 AM7/31/09
to Django users
Karen hi,

Thanks for the reply. I think I narrowed it down to the way I
installed Python on this server. I can run django applications and
other python scripts just fine from the command line.

It turns out that a quick way to test my Python + Apache setup is
replace the .wsgi file with the following

import socket
def application(environ, start_response):
status = '200 OK'
output = 'Hello world!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

Notice how it bypasses django and tests to see if Python can actually
run in the apache context. If that doesn't work, then it surely means
Python has been installed incorrectly. I googled some more and found
out that Python needs to be installed 'for all users', instead of
'just for me' (there are some required registry settings the xampp
process won't be able to find unless Python has been set up as such).

I switched my .wsgi file back to what it was previously and now my
django app is running!

Thanks again.
Reply all
Reply to author
Forward
0 new messages