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!

    Computing, OS X , , , ,

  1. janne
    December 1st, 2011 at 11:22 | #1


    thanks for the info here! almost worked perfectly for me. i tried first info from here: http://www.activecollab.com/forums/topic/5844/ but it didn’t compile so i googled again and found your post and got imap installed. so cheers for this!

    however, i did get an error from
    make osx EXTRACFLAGS=”arch i386 -arch X86_64 -g -Os -pipe -no-cpp-precomp”, error was something about the architecture, which i did not save.
    so i used make command from the other post
    make osx EXTRACFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp”, which compiled just fine. maybe a typo in -arch option?
    plus i didn’t get that prce error.

    and now i have imap working perfectly on my mb lion!


  2. Chad Hutchins
    December 8th, 2011 at 20:55 | #2

    Hey Dan, thanks for putting this together! This is exactly what I need.

    I’m running into issues on step 3 when running ‘make’. I get the following errors:

    llvm-gcc-4.2: Invalid arch name : X86_64
    make[3]: *** [osdep.o] Error 1
    make[2]: *** [osx] Error 2
    make[1]: *** [OSTYPE] Error 2
    make: *** [osx] Error 2

    Any ideas why I’m getting those? I’m running on a Macbook Pro OSX 10.7.

    Any help would be appreciated! Thanks!

  3. Chad Hutchins
    December 8th, 2011 at 21:24 | #3

    Hey Dan, I ended up fixing my issue with making imap without extra EXTRACFLAGS flags, just simply used “make osx” and everything worked fine.

    I also didn’t run into the error on step 6 so I didn’t have to do step 7.

    Thanks again for writing this up!

  4. chalozin
    December 10th, 2011 at 13:32 | #4

    thanks so much for gathering all in one place.
    based on my experience trying to compile it, I’ve came across a minor fix needed on step #3

    missing a dash (“-“) before the first arch, and the second should be lower case “x” (X -> x).

    i.e. instead of :
    make osx EXTRACFLAGS=”arch i386 -arch X86_64 -g -Os -pipe -no-cpp-precomp”

    should be:
    make osx EXTRACFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp”

  5. December 20th, 2011 at 21:57 | #5

    Hi, works for me! thanks!
    only one thing:

    on “make osx EXTRACFLAGS=”arch i386 -arch X86_64 -g -Os -pipe -no-cpp-precomp””
    the x of “X86_64” should be in lowercase “x86_64” (my compiler cry with X)

    I install pcre with “brew install pcre” and works fine too.

    thanks a lot! and sorry for my english 😛

  6. Randy Cramp
    January 3rd, 2012 at 03:21 | #6

    Thanks so much! This saved me countless hours! I had just one issue with one of your lines:

    make osx EXTRACFLAGS=”arch i386 -arch X86_64 -g -Os -pipe -no-cpp-precomp”

    I needed it to be:

    make osx EXTRACFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp”

    Note the lowercase “x” for the “x86_64”. Otherwise, I was getting “invalid arch name”.

    Thanks again!

  7. Ben
    January 11th, 2012 at 18:58 | #7

    Thank you so much for this guide Dan.

    This saved me a lot of frustration after trying all sorts of guides and all of them running into some undocumented problem.

    So, thanks again!

  8. Yves
    February 13th, 2012 at 21:56 | #8

    Thanks for all the tips. On my July 2011 Mac Air w/Lion PCRE was present but I had a different strange problem with the imap MAKE:

    error: ‘PHP_FE_END’ undeclared here (not in a function)

    which required me to hack into the php_imap.c file and follow these instructions: http://serverfault.com/questions/317463/php-fe-function-c-error-when-trying-to-enable-extension

    I was then able to make and complete as show above.

  9. February 22nd, 2012 at 06:11 | #9

    Thanks! Many problems averted with this!

  10. Indus
    March 15th, 2012 at 12:37 | #10

    Followed step-by-step. Worked like charm. Mac OS X 10.7.2, Intel i7. Thanks!

  11. John Baldwin
    April 26th, 2012 at 23:04 | #11

    I got stopped up on Step 8 at the make statement. It failed, reporting that PHP_FE_END and ZEND_MOD_END were not defined:

    …../php_imap.c:554: error: ‘PHP_FE_END’ undeclared here (not in a function)
    …../php_imap.c:561: error: ‘ZEND_MOD_END’ undeclared here (not in a function)

    I replaced these symbols in php_imap.c with their definitions that apparently didn’t come through.

    PHP_FE_END => { NULL, NULL, NULL, 0, 0 }

    I’m running Lion 10.7.3 and PHP 5.3.8 (stock).

  12. Eric Windham
    June 27th, 2012 at 15:37 | #12

    I know you wrote this a while back. When I ran ‘make’ on the for the imap libraries, the c-client.a file was not created. Do you have any idea why that is?


  13. Aaron
    November 30th, 2012 at 10:33 | #13

    I recently came across your post. I’m running Mac OS X 10.6.8, do you think I can also follow these steps? I checked the PHP version and I have 5.3.15. I assume that I need to download the same source to properly do this. If you can let me know I’d really appreciate it.

  14. December 17th, 2012 at 10:33 | #14

    I had to use the following command for Step 3:
    make osx EXTRACFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp”

    Thanks a bunch very useful article.


  15. January 9th, 2014 at 00:12 | #15

    Thank you for these instructions. I’ tried to install the php imap module on my Snow Leopard mail server, and was getting the error you mentioned: “configure: error: utf8_mime2text() has new signature,” etc.

    I am trying out your solution but could not execute this line:

    sudo cp c-client/c-client.a /usr/local/lib/libc-client.a

    The file “c-client/c-client.a” does not exist in the imap-2007f I downloaded and extracted. There is however a file called “c-client/c-client.h”

    I tried substituting that one but still cannot get this to compile. Any advice would be most appreciated.

  1. October 16th, 2012 at 16:34 | #1
  2. December 21st, 2012 at 13:11 | #2