mime_magic on Mac OS X

Propeller head alert: Most of you won’t be interested in this, but I had to get the mime_magic module working with Apache/PHP on Mac OS X 10.4 this morning, and thought I’d write up the steps.

The following steps require the XCode developer tools to be installed on your system (these are included on the Mac OS X install CDs). The steps also assume that PHP4.4.1 is installed (the default for 10.4.4+).

Apache

  1. Uncomment the following lines in /etc/httpd/httpd.conf
    LoadModule mime_magic_module libexec/httpd/mod_mime_magic.so
    AddModule mod_mime_magic.c
  2. Update the following section to reflect your system setup
    <IfModule mod_mime_magic.c>
    MIMEMagicFile /etc/httpd/magic
    </IfModule>

PHP

  1. Download the matching version of PHP for your system.
  2. Extract archive and go to the “/ext/mime_magic” in the extracted directory.
  3. Open terminal and run:
    phpize
    ./configure
    make
    make install
  4. Note down the installed directory
  5. Update extension_dir value to match installed directory – e.g.:
    extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20020429/"
  6. Add a section to PHP.ini containing:
    [mime_magic]
    extension=mime_magic.so
    mime_magic.magicfile = "/etc/httpd/magic"

    where “/etc/httpd/magic” matches your system setup
  7. Restart apache (using Sharing system preference pane)

Thanks to Andrew at RWTS for walking me through most of the above to get it running…

Update: Unfortunately this breaks when using PHP from the command line. Keeps complaining about:

NSLinkModule() error
Symbol not found: _OnUpdateString

Any thoughts much appreciated…

Update 01-Sep-2006: With some more help from Andrew I recompiled PHP (with mime_magic as a compile option) and the problem is resolved. Had issues with PEAR, but was able to resolve them using the PEAR bits of this tutorial (I had to run curl http://go-pear.org | sudo php).

It all seems to be working, but we’ll wait and see if anything else comes up…