Home > Computing, OS X > PHP IMAP support in Mac OS X Lion without recompiling PHP

PHP IMAP support in Mac OS X Lion without recompiling PHP

November 24th, 2011

OK, so this was a lot harder than it should have been, and I had to use various tutorials to get it working, however I am pleased to say that I finally did get it all working without needing to completely recompile php. Here are the steps:

First, modified from http://blog.xeonxai.com/2009/12/03/160/:

  1. Download IMAP source code (now 2007f).
  2. Extract the tar.gz file (double click it in finder or tar xvzf imap-2007f.tar.gz in terminal)
  3. Then, modified from This Comment on the same xeonxai blog post, do the following to avoid the error:
    "configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information." when executing item 6 in this tutorial.
    cd ~/Downloads/imap-2007f
    make osx EXTRACFLAGS="arch i386 -arch X86_64 -g -Os -pipe -no-cpp-precomp"
    sudo cp c-client/*.h /usr/local/include/
    sudo cp c-client/*.c /usr/local/lib/
    sudo cp c-client/c-client.a /usr/local/lib/libc-client.a
  4. Then download php source. Make sure you get the right source (you can check your php version by the command in the terminal: php -r "phpinfo();" I think OS X Lion standard install is php 5.3.6 which you can download at http://es.php.net/get/php-5.3.6.tar.bz2/from/a/mirror
  5. Unpack php-5.3.6.tar.bz2 (double click it in finder or tar xvzf php-5.3.6.tar.bz2)
  6. In Terminal:
    cd ~/Downloads/php-5.3.6/ext/imap
    ./configure --with-imap==/usr/local/imap-2007 --with-kerberos --with-imap-ssl

    At the make command, things will fail. This is the message that I got…
    In file included from /Users/danspencer/Downloads/php-5.3.6/ext/imap/php_imap.c:44:
    /usr/include/php/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory
    In file included from /Users/danspencer/Downloads/php-5.3.6/ext/imap/php_imap.c:44:
    /usr/include/php/ext/pcre/php_pcre.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    /usr/include/php/ext/pcre/php_pcre.h:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    /usr/include/php/ext/pcre/php_pcre.h:44: error: expected specifier-qualifier-list before ‘pcre’
    make: *** [php_imap.lo] Error 1

    Basically, pcre is not installed, so we need to install this first. See next step!
  7. Modified from http://blog.xavicolomer.com/2011/09/06/osx-lion-and-nginx-installation-tutorial/:
    • Download PCRE from the Sourceforge Project page: http://sourceforge.net/projects/pcre/files/pcre/8.20/pcre-8.20.tar.gz/download
    • Untar the file: tar xvzf pcre-8.20.tar.gz
    • cd to the directory: cd pcre-8.20
    • configure and make: .configure --prefix=/usr/local<br />make<br />sudo make install
    • Successful installation should look like the following in the last couple of lines:
      test -z "/usr/local/include" || ./install-sh -c -d "/usr/local/include"
      /usr/bin/install -c -m 644 pcre.h pcrecpparg.h pcre_stringpiece.h '/usr/local/include'
      test -z "/usr/local/lib/pkgconfig" || ./install-sh -c -d "/usr/local/lib/pkgconfig"
      /usr/bin/install -c -m 644 libpcre.pc libpcreposix.pc libpcrecpp.pc '/usr/local/lib/pkgconfig'
  8. Now you should be able to cd to the imap extension directory in php-5.3.6 source and compile the extension:
    cd ~/Downloads/php-5.3.6/ext/imap
    ./configure --with-imap==/usr/local/imap-2007 --with-kerberos --with-imap-ssl
    sudo cp modules/imap.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
  9. Now edit php.ini (sudo vi /etc/php.ini) and add the imap extension in (I added mine around line 990, just under the commented out windows extensions. in vi, you will need to press i to insert text):
    ;IMAP Extension

    After editing, save the file (in vi press esc to exit insert mode, then type “:x”).
  10. now restart apache, and we should be done! sudo apachectl graceful
  11. To test to see if we are up and running, we can do a couple of things…
    • php -r "phpinfo();"
      We should be able to find the following in the output (the modules are in alphabetical order):

      IMAP c-Client Version => 2007f
      SSL Support => enabled
      Kerberos Support => enabled

    • You can also check to see if the imap functions exist:
      php -r "if(function_exists('imap_open')) { echo 'imap_open exists!'; } else { echo 'imap_open does not exist'; }"
      You should get an output of “imap_open exists”
  12. So that’s it, hope it helps!

    Dan Spencer Computing, OS X , , , ,

  1. No comments yet.
  1. No trackbacks yet.