Server : Apache 2.2
OS : Mac OS X 10.5.4
Python : Version 2.5.1
Django : Version 1.0.2 final
Machine : Mac Mini

Mod_python is a loadable Apache module which embeds the Python interpreter, so Python code can be run in-process by Apache. To deploy and run your Django application in an Apache web server you have to
- Download and install mod_python
- Load it in Apache
- Configure Apache to run the Django app.
In this post I’m going to share my experience on how to do all that on a Mac Mini that runs on OS X 10.5.
The Software & Hardware
Here was my system configuration
- Server : Apache 2.2
- OS : Mac OS X 10.5.4
- Python : Version 2.5.1
- Django : Version 1.0.2 final
- Machine : Mac Mini running on 2.0 GHz Intel Core 2 Duo processor with 2GB RAM
1. Get the mod_python source
Check out the mod_python source code from the remote SVN repository*
$ svn co https://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk/ mod_python_src/
*The reason I’m downloading the source from an SVN trunk and not from the Apache website, is because the source available at the later one isn’t properly patched for Mac Mini’s architecture. In my earlier attempts, when I downloaded and built mod_python from stable releases, Apache was failing to start whenever the mod_python module was being loaded using the LoadModule Directive.
2. Build the source
$ cd mod_python_src
$ ./configure --with-apxs=/usr/sbin/apxs
$ make
$ sudo make install
3. Configure Apache to load mod_python when it starts
Open the Apache configuration file
$ sudo vi /etc/apache2/httpd.conf
Add the following line to the file
LoadModule python_module libexec/apache2/mod_python.so
Now restart Apache
$ sudo /usr/sbin/apachectl restart
4. Configure Apache for Django
Let’s suppose you have a Django app callled “mysite”. Copy you the directory to the Apache DocumentRoot
$ cp -r /path/to/mysite /Library/WebServer/Document/
Add the following lines to the httpd.conf file
<Location "/mysite">
SetHandler python-program
PythonPath "['/Library/WebServer/Documents'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonAutoReload On
PythonDebug On
</Location>
This’ll make Apache to route any requests under URL “/mysite” to the mod_python handler. It passes the value of DJANGO_SETTINGS_MODULE so mod_python knows which settings to use.
Now restart Apache and go to the site http://localhost/mysite
If it works then congratulations! You’ve just deployed your app on Apache!
Troubleshooting tip(s)
If Apache fails to launch after you’ve installed and loaded mod_python, run it in debugging mode
$ sudo /usr/sbin/httpd -X
Look for any error message printed in the terminal, copy it and google it. You may find a solution online.
You should also check out