Apache 2.2 and mod_python on OS X
While working on a forthcoming project (watch this space...), I decided it'd be a lot easier to test the code on my local machine rather than SUCS's server.
Tiger (yes, I'm a Mac user these days) comes with Apache 1.3, which is rather outdated, so I looked into updating to a more recent release. Fink has Apache 2.0, but I decided to go all-out and try and get Apache 2.2 running. It turned out to be relatively easy.
Here's my setup:
- OS X 10.4.7 on an Apple MacBook
- XCode 2.3
- Python 2.4.3 from python.org
First of all, we need to get Apache compiled and installed.
$ wget http://www.mirror.ac.uk/mirror/ftp.apache.org/httpd/httpd-2.2.3.tar.gzThat should install Apache into
$ tar zxf httpd-2.2.3.tar.gz
$ cd httpd-2.2.3
$ ./configure --with-mpm=worker --enable-so
$ make
$ sudo make install
/usr/local/apache2.Next, download and compile mod_python:
That'll build mod_python and put the appropriate files in
$ wget http://www.mirrorservice.org/sites/ftp.apache.org/httpd/modpython/mod_python-3.2.10.tgz
$ tar zxf mod_python-3.2.10.tgz
$ cd mod_python-3.2.10
$ ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/local/bin/python
$ make
$ sudo make install
/usr/local/apache2/modules.Configuring our newly-compiled Apache to replace OS X's default one is easy enough - a few changes to /usr/local/apache2/conf/httpd.conf and extra/httpd-userdir.conf is all it takes. Download an archive with all the necessary patch files here. Note - these configuration changes don't cause Apache 2 to behave exactly like Tiger's Apache 1.3, and there may be parts I've overlooked that could be exploited.
To apply the patches, run the following as root (from the directory with the extracted contents of the archive):
# patch /usr/local/apache2/conf/httpd.conf httpd.conf.patch
# cp httpd-userdir.conf /usr/local/apache2/conf/extra/.
By now, you should have a working Apache 2 setup on your Mac, but how can we make it start at boot? This is relatively easy - we can use /Library/StartupItems to accomplish this. The zip file contains the files you need to put in this directory to automate Apache's startup.
Unzip the archive and then cp -r Apache2 /Library/StartupItems/. as root.
That's it! To get the server started, you can run sudo /sbin/SystemStarter start "Web Server" and then browse to http://localhost/ to test your new Apache installation! And then, of course, you can dive into the world of Python.
[ Entry posted at: Thu 17 Aug 2006 00:00:52 BST | 2 comment(s)... | Cat: Geeky ]

Harry writes:
I tried to install Apache 2.2.3, but it doesn't start.
If I start it with sudo I get no output at all and it doesn't run as far as I can tell. Without sudo I just get a strange error.
Any ideas why this happens ?
Looks like this in Terminal:
$ sudo /usr/local/apache2/bin/apachectl start
$ sudo /usr/local/apache2/bin/apachectl stop
httpd (no pid file) not running
$ /usr/local/apache2/bin/apachectl start
(13)Permission denied: make_sock: could not bind to address [::]:80
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
[ Fri 08 Sep 2006 17:44:53 BST ]
Dave Arter writes:
Have you tried connecting to localhost in your web browser after starting the server with sudo?
I don't get any output either - in general, no output from a unix command means it was successful.
The errors you get when trying to start apache without using sudo are because the httpd process will start as your user, and non-root users can't bind to privileged ports (
[ Wed 27 Sep 2006 22:30:36 BST ]