Home

Hello. My name is Noemi Millman, and Triopter is my web development agency. We handcraft beautiful, dynamic websites.

See what I can do for you.

Noemi Millman: Triopter: Adventures in DarwinPorts (Installing Apache2, PHP5, MySQL 4.1, PostgreSQL, and Django)

Adventures in DarwinPorts (Installing Apache2, PHP5, MySQL 4.1, PostgreSQL, and Django)

Yeah, that’s quite a mouthful.

I decided a couple weeks ago that I wanted to learn Django as well as Ruby on Rails. Django is a little bit less trendy, but seems to have more flexibility, and gives you an entire admin section of your app “for free”, as opposed to RoR, for which there are a zillion different ways to hack on user management, and no sense of “best practices” for a novice.

Django requires an up-to-date installation of Python, and a number of other dependencies, including a database API for Python. The best installation instructions I could find for OS X (one of the reasons I use a Mac is the availability of all these great UNIX tools that are so useful for a webmaster) recommended using DarwinPorts (soon becoming MacPorts) to simplify installation.

DarwinPorts is awesome.

Getting the Latest Apache / PHP / MySQL

I peeked through the list of available packages, and decided that as long as I was at it, I might as well add an Apache 2 / PHP 5 / MySQL 4.1 server to run on port 81 alongside the default Apache 1.3 / PHP 4 / MySQL 4.0 that I already had on port 80.

An earlier attempt to do this had run out of steam as I realized I would have to choose, locate, configure, and compile all my Apache modules by hand, which is really beyond my ability and ambition. But DarwinPorts would allow me to install Apache with a whole bunch of common modules included, and would download and install all the dependencies for each one automatically.

Well, even on my top-of-the-line-a-year-ago machine, this stuff takes a while to compile, but about an hour later (after cursing at myself for misunderstanding the sudo -u mysql command as running MySQL and trying to fix an error by prepending a path to the username) I had a working secondary server. DarwinPorts not only installs dependencies for each piece, and not only configures everything for you, and not only reminds you of changes to make to your $PATH variable in case the installer couldn’t, but sometimes it even tells you what commands to run after installing each program to properly do things like initalize databases. Sweet.

Here’s how you do this:

  1. port install mysql4 +server
  2. port install apache2 +server
  3. port install php5 +mysql4 +apache2
  4. copy httpd.conf.sample to httpd.conf
  5. [optional] change path in DocumentRoot and associated directives
  6. [optional] change Listen 80 to Listen 81 (If you want to run side-by-side with an Apache 1.3 installation on port 80)
  7. add the following to the directive:
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

Don’t forget to follow the extra directions DarwinPorts gives you.

Python, PostgreSQL, and Psycopg Spell Problems

I easily updated my Python installation, and then I ran into trouble. You see, the instructions I had for DarwinPorts were for installing with SQLite. I wanted to use PostgreSQL, partly because I figured it would be a useful thing to learn, and partly because skimming the initial tutorial and its comments had showed me that PostgreSQL was perhaps the optimal database choice because of its handling of foreign key constraints.

The main installation instructions for OS X used PostgreSQL, but compiled it by hand.

So I decided to wing it. The DarwinPorts available ports list included three versions of the PostgreSQL package, so I picked the latest one (postgresql81), and installed it. Then I installed the next dependency (py-egenix-mx-base). No problem. And then I ran into the final piece, psycopg.

Psycopg is a package that allows Python to interact with PostgreSQL databases. The instructions were very specific about installing version 1.1, not version 1.0 or 2.0, of psycopg. Great. I asked DarwinPorts to install psycopg.

Well, first problem: the DarwinPorts psycopg package depends on the postgresql8 package, not postgresql81.

Second problem: every server from which it attempted to download postgresql8 timed out.

I was a little bit flummoxed at this point.

I backtracked, downloaded the source code for psycopg, compiled it by hand using the main OS X installation instructions (I had to tweak a lot of paths to reference DarwinPorts’ installation locations), and boom! I’m off and running.

Phew.

I feel like an idiot for not documenting the exact commands I used, for the edification of future generations. If I ever do this again and am not running down blind alleys looking for solutions to problems caused by my own typos, I promise to do so faithfully. In the meantime, here are the steps to do it the easy way (assuming the postgresql8 servers are working):

  1. sudo port install python24
  2. sudo port install postgresql8
  3. sudo port install py-egenix-mx-base
  4. sudo port install py-psycopg
  5. [optional] sudo port install subversion (If you’re using the development version of Django, or just want subversion)
  6. Install Django

Next up, I’ll tell you what it’s like to jump from MySQL to PostgreSQL, and all about my experiences with the Django tutorial.

  1. COMMENT: by Scott Anderson, December 5th, 2006

    Oh, man… I really wish you had written that stuff down, because I’m struggling with the exact same problem right now.

    I’m trying to compile it manually from the Darwin port of 8.1.5 but with no luck.

    -scott

  2. COMMENT: by Scott Anderson, December 5th, 2006

    Well, I may have solved my issue.

    I edited the psycopg port file to reference postgresql81 instead of postgresql8:

    /opt/local/var/db/dports/sources/rsync.rsync.darwinports.org_dpupdate_dports/python/py-psycopg/Portfile

    I also had to change pgsql8 to postgresql81 in that file to reference the proper configuration directory.

    Then, from that directory, I did ‘sudo port install -f current’.

    -scott

  3. COMMENT: by Noemi Millman, December 5th, 2006

    Oh – that sounds a lot more sensible than what I did. I didn’t realize it was so simple to edit a port. Thanks for posting that!

    I basically followed the “Install Psycopg” instructions at http://code.djangoproject.com/wiki/SetupOnTiger, changing the path in step 7 (and I think the note about mxDateTime) to refer to the path where DarwinPorts installs stuff. Unfortunately, as I mentioned, I don’t have the exact commands I used.

    Did everything work out for you?

  4. COMMENT: by Scott Anderson, December 6th, 2006

    I didn’t realize it was so simple either, until I tried it. ;-)

    And yes, it works fine. I tried just changing the path as you did, but ran into a number of linking issues with the rest of the Darwin Port stuff. In the end it was easier to modify the port itself. I’m surprised no one has fixed it yet.

    I tried modifying the Django page, but the software there claimed that my changes were spam. Hrmph.

  5. COMMENT: by Triopter » Six Steps to a Subversion Server on OS X with Darwinports, December 29th, 2006

    [...] Grab Apache 2 off Darwinports and get it running separately from the default OS X Apache 1.3 installation (PHP, MySQL, et al entirely optional). Darwinports’ Apache automatically includes mod_dav, which you’ll need. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

Comments may be held for moderation to prevent spam: your comment may not appear immediately.