Installing IMAP extension for PHP on Mountain Lion

Based on Dao Hoang Son’s tutorial (itself based on Dan Spencer’s Lion tutorial), as well as a few corrections of my own, I came up with the following script. It fetches and installs University of Washington’s IMAP library, then the PCRE – Perl Compatible Regular Expressions library, and finally the PHP IMAP extension itself.

Please study the script yourself before running it, or run it line by line. It performs no error checking, meaning it might totally wreck your machine — and I’m not responsible if it does. Keep a Time Machine backup around and unplugged from the computer, in case it does.

The script wasn’t yet tested in its complete form; it’s an approximate transcript of commands I ran in shell. But since I’ll keep it around in case I ever need to re-run it, I’m fairly certain it works.

UPDATE December 24th 2012 – Merry Christmas! I’ve applied corrections based on Mehmet’s comment. He also comments you need to install autoconf before running the script (so phpize can work). I already had it installed.

Filesizes for stuff I downloaded: 1.990.304 – imap-2007f.tar.gz, 1.539.766 – pcre-8.20.tar.gz, 12.926.535 – PHP-5.3.15.tar.gz

#!/bin/bash
BUILDDIR=/tmp/phpimapmountainlion

mkdir "$BUILDDIR"
echo " "
echo "= FETCHING AND INSTALLING IMAP"
echo " "
cd "$BUILDDIR"
wget -c ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz
rm -rf imap-2007f
tar xvvfz imap-2007f.tar.gz
cd imap-2007f
make osx EXTRACFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
sudo mkdir -p /usr/local/imap-2007f/include
sudo cp c-client/*.h /usr/local/imap-2007f/include
sudo mkdir -p /usr/local/imap-2007f/lib
sudo cp c-client/c-client.a /usr/local/imap-2007f/lib/libc-client.a

echo " "
echo "= FETCHING AND INSTALLING PCRE"
echo " "
cd "$BUILDDIR"
wget "http://sourceforge.net/projects/pcre/files/pcre/8.20/pcre-8.20.tar.gz"
rm -rf pcre-8.20
tar xvvfz pcre-8.20.tar.gz
cd pcre-8.20
./configure --prefix=/usr/local
make
sudo make install

echo " "
echo "= FETCHING AND INSTALLING PHP-IMAP"
echo " "
cd "$BUILDDIR"
PHPVERSION=`php --version|head -n1|cut -f 2 -d ' '`
##git clone -b "PHP-$PHPVERSION" https://github.com/php/php-src.git php-src
wget --no-check-certificate -c https://github.com/php/php-src/tarball/PHP-5.3.15 -O PHP-5.3.15.tar.gz
tar xvvfz PHP-5.3.15.tar.gz
cd `ls |grep php-php-src-|head -n1`
cd ext/imap
phpize
./configure --with-imap=/usr/local/imap-2007f --with-kerberos --with-imap-ssl
make
sudo cp modules/imap.so /usr/lib/php/extensions/no-debug-non-zts-20090626/


via blog.vucica.net

12 thoughts on “Installing IMAP extension for PHP on Mountain Lion

  1. Mehmet Avcioglu

    Mistakes on the script:
    mkdir lines also need sudo
    wget PHP-5.3.15 line has the "tar.gz" on a different line, needs to be appended at the end as "PHP-5.3.15.tar.gz"
    Mountain Lion also needs autoconf installed before phpize can run

    Reply
  2. Joel

    I have PHP 5.4.9 – after I did this I always see this error:

    PHP Warning: PHP Startup: imap: Unable to initialize module
    Module compiled with module API=20090626
    PHP compiled with module API=20100525

    Is there a newer IMAP version available? I have searched and cannot find it.

    Reply
  3. Dragos

    Great script! Thank you very much! It really helped me.
    I would even add some more links for the next visitors of this page.

    wget is also not a standard on Mountain Lion anymore.
    There could be a fallback solution with cURL:
    curl -O http://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.gz
    or one could install wget, really easy instructions here: http://osxdaily.com/2012/05/22/install-wget-mac-os-x/

    For autoconf install instructions: http://recensus.com/blog/technical/installing-autoconf-and-fixing-phpize-on-osx-10-8/

    One should not forget to add the new compiled extension in the php.ini and then restart apache (this is written in Dao Hoang Son's article though, so anyone reading carefully this article should already know that 🙂

    Reply
  4. Ivan Vučica Post author

    As a small comment: the reason why I didn't write about install instructions for wget or autoconf is because I already use MacPorts and, lately, Homebrew.

    Homebrew's homepage

    You can install Homebrew using the one-liner shown on that page (which should be all that you need on a machine that already has Xcode with command line tools):

    ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

    I simply do stuff like brew install wget. (I'm lying, because I actually installed wget a few years ago with MacPorts. But Brew's bound to have wget, too.)

    See more about installing Homebrew.

    Reply
  5. Stewart Adam

    I tried this on 10.8.3 and got several linker errors (ld: symbol(s) not found for architecture x86_64 after complaints about various missing symbols like _SSL_pending, _SSL_CTX_set_tmp_rsa_callback, _ERR_load_crypto_strings, _BIO_free, etc) and just wanted to say your script works perfectly, but it needed one minor modification in my case to add the extra linker flags "-lssl -lcrypto". I have compiled the details here: http://www.firewing1.com/node/630

    Reply
  6. brantwynn

    Looked this over, ran it, and it worked for me.

    I already had wget and autoconf ready to go.

    After running the script, I needed to follow the last two steps from Dao Hoang Son's blog:

    1. add the extension to php.ini
    extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/imap.so

    2. restarted apache.
    sudo apachectl restart

    Then it was good…

    Thanks, ivucica!

    Reply
  7. Fernando Antunes

    Sorry my english, efetuei all the steps, when I found the last line:

    sudo cp modules / imap.so / usr/lib/php/extensions/no-debug-non-zts-20090626 /

    does not find the file imap.so what might have happened? wait, thanks

    Reply
    1. tedivm

      This was address further up. Simply swap out-


      ./configure --with-imap=/usr/local/imap-2007f --with-kerberos --with-imap-ssl

      With-


      LDFLAGS="-lssl -lcrypto" ./configure --with-imap=/usr/local/imap-2007f --with-kerberos --with-imap-ssl

      Reply
  8. Robert

    I updated this script to make it more future proof. It creates a few directories that may not be there, it pulls in the php version dynamically, and it makes it pretty easy to update the versions of the other components. As a final addition it had some additional output to tell people how to clean up and what to add to their php.ini file to make it work.

    You can find the updated version on Github-

    https://github.com/tedivm/PHP_IMAP_Installer_OSX

    Reply
  9. Pingback: PHP IMAP Script | tedious ramblings

Leave a Reply

Your email address will not be published.

 

What is 6 + 8 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

This site uses Akismet to reduce spam. Learn how your comment data is processed.