Installing Apache 2.2 on OSX with mod_python
September 23rd, 2007
Following on from setting up Django on your local system for dev purposes, I thought id just do an article about how to set up apache to use mod_python for when you want to roll your Django app out to the big bad world.
Before you start, you will NEED to have completed the other post about installing Django, as you need to have the mac python installer in and configured properly for this to work.
Step 1
First of all we’ve got to get Apache 2.2 working, as Apple only ship 1.3 with OSX (I wonder if this will change in Lepord? Lets hope so!). You can download the source here.
Extract the archive and cd into the new directory. We need to configure it with some options so that we have proxying (which you might want for rails etc) and just some other candy you might find usefull at a later date.
Set the CFLAGS:
export CFLAGS=”-arch i386″
Run this configure command:
./configure \
--prefix=/Library/Apache-2.2.6 \
-–enable-so \
--enable-mods-shared=all \
--with-mpm=prefork \
--enable-dav \
--enable-cache \
--enable-proxy \
--enable-shared \
--disable-static \
--disable-unique-id \
--disableipv6 \
--enable-logio \
--enable-deflate \
--with-ldap \
--with-ldap-include=/usr/include \
--with-ldap-lib=/usr/lib
--with-included-apr
--enable-ldap \
--enable-auth-ldap \
--enable-cgi
--enable-cgid \
--enable-suexec
Let it do its business then run the usual:
make
then
make install (NB: we dont use sudo here as that way apache is compiled with permisions that let you edit the conf files and so on without needing to be an admin which is just ‘nicer’ for local dev)
Step 2
Configure your httpd.conf file as you see fit. I only really felt the need to change the following:
Change user and group to your user name (or any other one you want) Change ServerAdmin email to an appropriate one Uncomment “Include conf/extra/httpd-mpm.conf” Uncomment “Include conf/extra/httpd-default.conf” Add “NameVirtualHost *” for virtual hosting
My personal preference is then to have an “applications” folder in the apache conf dir, for which I then add a directive to httpd.conf to load in per-application virtual hosting configurations. It just keeps it nice and clean that way.
mkdir /Library/Apache-2.2.6/conf/applications
Include conf/applications in httpd.conf (in your httpd.conf)
Step 3
If you havent already, grab mod_python from here. Extract, it and cd into the directory.
You’ll then need to configure it with the following command:
./configure -–with-apxs=/Library/Apache-2.2.6/bin/apxs \
-–with-python=/Library/Frameworks/Python.framework/Versions/Current/bin/python
Then do make and sudo make install
Provided you got no errors upon compilation, all should be well. You just need to add another line to your httpd conf:
LoadModule python_module modules/mod_python.so
Step 4
Poor yourself a nice cuppa!
Running Django on OSX
September 22nd, 2007
No doubt you’ve heard about the new python web framework thats making some waves at the moment - Django.
As with most *nix developers, im running OSX (10.4), and wanted to get a working Django dev environment function to have a play around with it and found that a needed to mess around with a few things to get it working, so I thought id post them up here in case anyone else found them usefull :)
Step 1
Download the python-mac installer from here and run it. That will give you a working version of the latest python bin.
Step 2
Checkout the latest version of Django source like so
cd /usr/local
svn co http://code.djangoproject.com/svn/django/trunk/ django
Step 3
If you used the python installer for mac, then the below will work, otherwise, you’ll need to just tweak the path’s a bit:
ln -s /usr/local/django/django /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django
Step 4
Add the django source to your path:
PATH=/usr/local/django/django/bin:$PATH
Then that should be it :) However, if your a touch on the forgetfull side when using the terminal, it can be annoying having to keep putting the .py on the end of the django commands, so we’ll just quickly symlink them so if we forget to add .py, it wont slap us with a kipper
cd /usr/local/django/django
ln -s django-admin.py django-admin
Then your all done! Enjoy Django :)