Version 2 (modified by anonymous, 10 years ago) (diff)


Getting Django to work with Apache 1.3 and FCGI on Mac OS X

On OS X, using django with mod_python requires you to install Apache2, which involves quite a bit of extra effort to get it right. So for most of us Mac users, this is not an option. At the same time, the information contained here Django, Apache and FCGI and here django projects was a bit incomplete from a Mac users perspective.

So here is a summary of the steps needed to get Django working with FCGI and Apache 1.3 on Mac OS X: It assumes that your django project is called myproject. Adjust the following accordingly.


download the django-fcgi-py script and install it in /usr/local/bin

curl -k -o ''
sudo chmod a+x
sudo mv /usr/local/bin

install mod_fastcgi

straightforward apache module install

curl -O
tar xvfz mod_fastcgi-2.4.2.tar.gz 
cd mod_fastcgi-2.4.2
/usr/sbin/apxs -o -c *.c
sudo /usr/sbin/apxs -i -a -n fastcgi

install latest flup

again, this is straightforward

svn co flup
cd flup/
sudo python install
cd ..
sudo rm -rf flup

change /etc/httpd/httpd.conf

use your favorite editor to add the following lines at the end:

FastCgiExternalServer /Library/WebServer/Documents/django.fcgi -host
<VirtualHost *:80>
    Servername django.loc
    ErrorLog /var/log/httpd/django-error.log
    CustomLog /var/log/httpd/django-access.log combined
    DocumentRoot /Library/WebServer/Documents/
    RewriteEngine On
    RewriteRule ^(/admin.*)$ /django.fcgi$1 [L]
    RewriteRule ^(/myapp.*)$ /django.fcgi$1 [L]

You'll need such a RewriteRule line for every application you want to access (if your application name is something else that myapp, make sure to change that above).

change /etc/hosts

add a 'django.loc' hostname, good for development	localhost	django.loc

give apache a restart with 'sudo apachectl restart'

link media files into docroot

so the django admin templates and style sheets are found. First, change into your django_src directory. And then:

ln -s `pwd`/django/contrib/admin/media /Library/WebServer/Documents/media

Now, change into your django project root (i.e. the directory that contains myproject), and link that into site-packages

sudo ln -s `pwd`/myproject /Library/Python/2.3/site-packages/myproject

Basically, import myproject should work now on the python prompt

starting and stopping

the following commands start the fcgi server, and stop it as well --settings=myproject.settings --host --port 8882 --daemon
kill `ps auxww | grep [d]jango-fcgi | awk '{print $2}'`

Note that the port-number in the call to has to match the number that you specified in (/etc/hosts)


with Apache and both running, you should be able to access the django admin at http://django.loc/admin

Back to Top