Mac OS X 10.4 + Python 2.4.3 + Django + Apache2 + mod_python

38 views
Skip to first unread message

Leo

unread,
Sep 24, 2007, 6:11:48 AM9/24/07
to Django users
I just went through getting set up for testing my Django apps under
mod_python as well as the test server. For the sake any other users
trying to sort through this on Mac OS X, I thought I'd post what
finally worked for me (YMMV). I assume you have a Django app working
under the test server, and you want to do what you think will be the
simple (haha) process of testing it under Apache locally.

Step 1: DevTools
We're going to be compiling from source. This means you must have a
recent copy of OS X DevTools installed. If you don't, go to
http://developer.apple.com/tools/ and download the newest fully-
released version (2.4 as of right now). Fortunately, I already had
Xcode all set up.

Step 2: Apache 2.0
If you want to test Django under mod_python, you're going to need to
upgrade to Apache 2.0 instead of the Apache 1.3 you currently have, as
mentioned here:
http://www.djangoproject.com/documentation/install/#install-apache-and-mod-python.

After looking at a few options, I concluded right now compiling from
source was the best option, none of the packaged updates seem to be up-
to-date right now with the latest security patches. Luckily, Apache
is a *very* clean build. Download a 2.X version (as of this writing,
it's 2.2.6) from an apache.org mirror. Then, look at the excellent
description of a Mac OS X setup for Apache here:
http://switch.richard5.net/isp-in-a-box-v2/installing-apache-on-mac-os-x/
Note that if you're using csh or tcsh instead of BASH, the first
command to set up your CFLAGS should be:
setenv CFLAGS "-arch i386 -isysroot /Developer/SDKs/
MacOSX10.4u.sdk"
instead of the bash syntax he's showing.

Step 3: mod_python
This was the most time-consuming part for me. It starts out easy,
just download mod_python 3.x source from http://www.modpython.org/
(right now the released version is 3.3.1). Unpack as usual.

The first step is to be sure to tell the configure program where your
Apache 2 installation is; if you followed the suggestions above it's
in /Library/Apache2. So with just that, your configure command will
be:
./configure --with-apxs=/Library/Apache2/bin/apxs

If you're using the Mac OS 10.4 default Python installation (2.3.5)
which is installed as a Framework in /Library/Frameworks, you can
continue to step 4 from there. However, I had upgraded to Python
2.4.3 and to remain version-locked with some other machines I really
wanted to keep using it. This caused two complications. The first
was to tell configure where my Python was, so my configure command
was:
./configure --with-apxs=/Library/Apache2/bin/apxs --with-python=/
usr/local/bin/python
That gets you through the configure, but it turns out to not quite
work. If you build, install, and run the mod_python from there, when
you launch Apache you'll get an error in the error_log to this effect,
and mod_python is useless:
[Mon Sep 24 13:21:56 2007] [error] python_init: Python version
mismatch, expected '2.4.3', found '2.3.5'.

Fortunately, Graham Dumpleton was nice enough to help me out, and
pointed out that after running configure but before running "make dso"
you need to edit the generated Makefile in src/Makefile. He has a
note about this on his page at
http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX
For me, since I had Python 2.4.3 installed in /Library/Frameworks, the
LDFLAGS line became this:

LDFLAGS= -Wl,-F/Library/Frameworks -u _PyMac_Error /Library/
Frameworks/Python.framework/Versions/2.4/Python -arch ppc -arch i386
-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g

Step 4: Go Back to Work on your App!
Whew! At that point, I finished compiling and installing mod_python,
then got to configuring my httpd.conf to reference mod_python, and
then finally got back to actually making my Django app work ;-)

Leo

P.S. I should also point out that Graham advised not using mod_python
at all, and using mod_wsgi, which is supposed to work with the stock
Apache 1.3 and python 2.3.5. My ultimate deployment server uses
Apache 2 so I stuck with the above, but for the sake of others I'll
pass along the reference I got:
http://www.modwsgi.org
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX

dstuart

unread,
Oct 4, 2007, 4:35:30 AM10/4/07
to Django users
Just a quick note to say mod_wsgi does support Apache 2 from the site:

"The mod_wsgi package can be compiled for and used with either Apache
1.3, 2.0 or 2.2 on UNIX systems (including Linux), as well as Windows.
Either the single threaded 'prefork' or multithreaded 'worker' Apache
MPMs can be used when running on UNIX.

Daemon mode of mod_wsgi will however only be available on Apache 2.0
or 2.2 running on UNIX, and only when the Apache runtime library
underlying Apache has been compiled with support for threading.

Python 2.3 or later is required and Python must have been compiled
with support for threading. "

Graham Dumpleton

unread,
Oct 4, 2007, 8:40:59 AM10/4/07
to Django users

FWIW, the reason I suggested that OP not use mod_python is because
when they first came to me it was about getting mod_python 2.7.11
working on MacOS X with Apache 1.3. To do this requires various
patches to be made to mod_python source code otherwise it will crash
when used. Thus the advice was based on them using Apache 1.3. It
looks like that they later decided to upgrade to Apache 2.X after I
had talked to them. Using mod_wsgi as I suggested was a way around the
need to patch old mod_python to get it working on MacOS X/Apache 1.3,
with mod_wsgi working on all major versions of Apache and Mac OS X as
is. So, bit of context was missing in the original post.

Graham

Reply all
Reply to author
Forward
0 new messages