I Can’t Get Mod_Python and Django Working on my Mac

For those that don’t know, Mac OS X includes a lot of open source software by default, including, for the purposes of this post, Apache and Python. The included Apache is 1.3 and Python is 2.35 in Mac OS 10.4, to be specific. Both, however, are out of date. This shouldn’t be a problem, but I cannot get mod_python working on Mac OS 10.4 with Apache 1.3 and Python 2.35. The current version of mod_python that is compatible with Apache 1.3 is 2.7.11.

After spending quite awhile trying to get mod_python to work on my Mac, I have concluded that it will not. It is possible that I am doing something wrong. I think that if I upgraded Apache and Python, it would be possible, but I really don’t want to override the default systems on my Mac.

All that aside, you don’t need mod_python to be able to run Django locally on the Mac. So I went through the process to install Django. Once that was done I tested it, and it tells me it is installed. But, once I try to run the Django tutorial, it fails.

I have tried this on 2 different Macs, and it failed on both of them. So I have given up until someone can point out what I did wrong or what I need to do to fix it. Even though the Mac has Python on it, for some reason neither mod_python or Django will run on it.


How to Restart Apache Locally on Mac OS X

Working with PHP and Apache locally on my Mac, I found myself needing to know how to restart Apache. The method I normally use did not work because for some reason etc/init.d does not exist or could not be found. So I found another command that worked. Simply run the following.

sudo apachectl graceful

graceful reloads the configuration files and gracefully restarts. Any current connections are allowed to complete. That’s it! You just restarted Apache. Easy huh?


Installing GD Graphics Library on Mac OS X

Recently, I needed to install the GD Graphics Library locally on my Mac. GD is an open source code library for the dynamic creation of images by programmers. GD creates PNG, JPEG and GIF images, among other formats. GD is commonly used to generate charts, graphics, thumbnails, and most anything else, on the fly. While not restricted to use on the web, the most common applications of GD involve web site development.

I searched through a lot of tutorials, and found that most of them are out of date and/or incomplete. In spite of this, I finally managed to figure it out. However, I took notes on everything I did so that someone else needing to do this will find this helpful and won’t have to struggle with it as much as I did.

I have to admit I am pretty green when it comes to using command line and installing open source code on my computer. I have learned a lot though and I really enjoy it. I have found that the Mac is a great open source programming environment. Many programmers are figuring this out, and I believe you will continue to see more programmers coming to the Mac platform.

Anyway, these instructions, as straightforward as they are, still assume you know the basics of how to install and run open source code on your computer. If you don’t, you need to go read more and then come back here. Now, let’s begin.

The first thing you need to do is download the packages you will need. Here is the commands you will use for the most current versions of these packages as of this posting.

curl -O http://www.zlib.net/zlib-1.2.3.tar.gz
curl -O http://superb-east.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.20.tar.gz
curl -O ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz
curl -O http://www.libgd.org/releases/gd-2.0.35.tar.gz

Download these packages to a directory on your hard drive. The next thing you need to do is unpack these directories. Running this command will unpack all the directories you just downloaded.

ls *gz | xargs -n 1 tar zxvf

First, we will install zlib by running the commands below.

cd zlib-1.2.3
./configure --shared
make
sudo make install

Next, install libpng by running the commands below.

cd ../libpng-1.2.20
cp scripts/makefile.darwin Makefile

Open up Makefile in your favorite text editor and edit the file to read as follows.

# Where the zlib library and include files are located
ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include
#ZLIBLIB=../zlib
#ZLIBINC=../zlib

Then finish the install.

make
sudo make install

Test this by running the following code.

export srcdir=.
./test-pngtest.sh

Next install libjpeg.

cd ../jpeg-6b/
ln -s `which glibtool` ./libtool
export MACOSX_DEPLOYMENT_TARGET=10.4
./configure --enable-shared
make
sudo make install

Now install freetype2.

cd ../freetype-2.3.5

Open include/freetype/config/ftoption.h in your favorite editor and uncomment line 461 to read as follows.

#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER

Then complete the install.

./configure
make
sudo make install

Finally install GD.

cd ../gd-2.0.35
ln -s `which glibtool` ./libtool
./configure

The report looked like this when I did it.

Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: no
Support for Xpm library: no
Support for pthreads: yes

Then finish the install.

make
sudo make install

You can test it with the following code.

./gdtest test/gdtest.png
open test/*.jpg

To add support for Fontconfig, run this command.

export GDFONTPATH=$HOME/Library/Fonts:/Library/Fonts:/System/Library/Fonts

To complete the installation, you need to recomple PHP with all the libraries you just installed. Here is how I did it.

./configure \
--with-zlib-dir=/usr/local/lib \
--with-jpeg-dir=/usr/local/lib \
--with-png-dir=/usr/local/lib \
--with-gd \
--with-mysql=/usr/local/mysql \
--with-apxs

make
sudo make install

Now you should have PHP with GDLIB installed. That’s it. You’re done! Now, on to your next project!


| Next Entries »

Most Popular Posts

Pages

Twitter Updates

Profiles