Sugar Developer Blog

Enabling IMAP support under OS X Leopard

26 Aug, 2008
Posted By: John Mertic

With the release of Mac OS X 10.5 Leopard last fall, Apple (finally) included a modern version of PHP (currently version 5.2.6 as of this writing). With it comes several improvements in the areas of performance, web services support (including extensions for JSON and XML), OOP, and error handling. However, the default install of PHP that Apple included didn’t include all of the available PHP extensions. Most notable is the IMAP extension, which is used in SugarCRM for the Campaigns and Emails modules. However you can build this extension and have it loaded dynamically, without affecting the rest of the default PHP install.

First, we’ll need to compile the c-client imap libraries, which can be obtained at ftp://ftp.cac.washington.edu/imap/. Notice the make command below; it has extra arguments added to be sure we are building the libraries as universal binaries, which is important since mod_php and apache are both compiled for 64-bit architecture.

$ curl -O ftp://ftp.cac.washington.edu/imap/c-client.tar.Z
$ tar -zxvf c-client.tar.Z
$ cd imap-2007b
$ make oxp EXTRACFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe -no-cpp-precomp"

We’ll then copy the libraries we built to the /usr/local directory, which is a place we can put any user-built programs and libraries and won’t affect the base system install.

$ 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

Next, we’ll grab the PHP tarball for the version of PHP we are using, which is currently 5.2.6, from the source: http://www.php.net/downloads.

$ curl -O http://www.php.net/distributions/php-5.2.6.tar.bz2
$ tar -xjf php-5.2.6.tar.bz2

Now we’ll go to the source directory of the imap extension and compile it. Again you’ll notice the additional agruments added for building the extension as a universal binary. ( Edit: note that the configure line below is multiple lines; each new command to enter is denoted by the $ at the beginning of the line, although the $ is not part of the command ).

$ phpize
$ MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe -no-cpp-precomp" \
CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" \
CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" \
LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" \
./configure --with-kerberos --with-imap-ssl
$ make
$ sudo make install
$ sudo echo "extension=imap.so" >> /etc/php.ini

Also, you’ll want to comment out the line ‘extension_dir = “./”‘ in the php.ini file, since it will interfere with the extension loading.

Finally, restart apache and you should see the imap extension listed in the output of phpinfo().

phpinfo() output showing imap enabled

Tags: , , , ,

13 Responses to “Enabling IMAP support under OS X Leopard”

  1. Trevor Jacques Says:

    I’d suggest that all the instruction lines be included in this posting, so that neophytes can follow every step properly. This would mean adding:

    sudo mkdir -p /SourceCache
    cd /SourceCache

    at the top of the instructions. Then, before “Next, we’ll grab the PHP tarball…” again add this:

    cd /SourceCache

    I’d also use the Apple-blessed latest php tarball at http://www.opensource.apple.com/darwinsource/10.5.4/apache_mod_php-44/php-5.2.5.tar.bz2 (Note that Apple has a directory tree for each Mac OS version.)

    The instruction “Now we’ll go to the source directory of the imap extension” needs to be spelled out:

    cd /SourceCache/php-5.2.5/ext/imap

    I’d recommend putting multi-line instructions on a single,unwrapped line in the browser, so that they can be reliably copied from the browser and pasted into the terminal window.

    After the configure, I did a make test and got all kinds of warnings and errors about signedness (for both Apple’s tarball and the php tarball). It does not seem that the instructions will work on Leopard Server. :-/

  2. John Mertic Says:

    Hi Trevor,

    It’s not a requirement to unzip and compile c-client and php in the /SourceCache directory; you can do it safely from any directory.

    Good point about using the Apple php tarballs. The only reason I didn’t use them is because Apple hasn’t yet released one for PHP 5.2.6, so I went and grabbed it from php.net instead.

    I’ve updated the post to make the configure line clearer, thanks for the tip!

    And don’t let the “pointer targets in assignment differ in signedness” warnings in the php compile worry you; as long as it compiles completely it will work just fine ( these warnings are common ). I tested this under Leopard Server and Client without any problems.

  3. JC Says:

    I’m with you all the way here, except that when I go to configure the imap module, I get:

    checking whether build with IMAP works… no
    configure: error: build test failed. Please check the config.log for details.

    config.log isn’t horribly helpful to mine eyes.

    it states:

    configure: failed program was:
    | /* confdefs.h. */

    and then, after some fairly generic defines and such, complains about:

    conftest.c:11:28: error: ac_nonexistent.h: No such file or directory

    Any ideas?

  4. John Mertic Says:

    Not exactly sure what the problem would be, but I would make sure you have all of the OS X security updates installed ( the latest one updates PHP to 5.2.6 ) and also make sure the archive you downloaded is not corrupt.

  5. Matt Says:

    The configure option did not work for me…but the rest of the instructions did. I simply used this instead for the ./configure command:

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

    Then, after doing make install, I was actually able to copy the imap.so file from /usr/lib/php/extensions/no-debug-non-zts-20060613/imap.so to the extension directory for MAMP, and it actually worked. Note that I also followed these instructions (http://jaspan.com/openssl-support-php-under-mamp) to enable OpenSSL earlier (don’t know if that made a difference).

    (Small note- create /usr/local/include/ if it does not exist before beginning the instructions)

  6. Russell Mathews Says:

    I’ve tried the above steps with no success. I even tried copying the imap.so into the apache2 extensions directory and adding it under the server monitor web piece which then caused apache to shutdown and I could not restart it. Any ideas as to what may be wrong? Thanks

  7. Juuso Tamminen Says:

    Finally got this working, thanks!

    I’m running OS X Server 10.5.5 on a G5 PowerMac. I fetched the PHP package from Apple. When I first tried to complie the programs with the “-arch ppc -arch ppc64″ (note that I have a non-intel processor) it always failed with the “checking whether build with IMAP works… no” error. Only after I removed the -arch ppc from the compile and configure commands it succeeded, I only used the -arch ppc64 option because that’s the only thing I needed.

    C-client was compiled with command:

    $ make oxp EXTRACFLAGS=”-arch ppc64 -g -Os -pipe -no-cpp-precomp”

    PHP IMAP module was configured with command:

    $ MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch ppc64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch ppc64 -g -Os -pipe” CXXFLAGS=”-arch ppc64 -g -Os -pipe” LDFLAGS=”-arch ppc64 -bind_at_load” ./configure –with-kerberos=/usr –with-imap-ssl=/usr –with-imap=/usr

  8. Alan Holding Says:

    I couldn’t get this working.

    I kept getting permission denied errors when running configure.

    In the end I…

    1. Downloaded and unpacked Apple’s PHP 5.2.5 archive (as linked to by Trevor Jacques above)

    2. Followed the instructions here: http://de3.php.net/manual/en/install.pecl.phpize.php, which meant (on my Mac) I did:

    cd /SourceCache/php-5.2.5/ext/imap
    phpize
    ./configure –with-kerberos –with-imap-ssl
    make
    make test

    Got some crazy progress text, but seemed to work.

    3. Copied /SourceCache/php-5.2.5/ext/imap/modules/imap.so to /usr/lib/php/extensions/no-debug-non-zts-20060613 (the zts-xxxx may be different for you).

    4. Commented out extension_dir = “./” in /etc/php.ini (at around line 600) - NOTE: This website seems to replace quote marks with typographically ‘correct’ one, so be careful if cut and pasting that.

    5. Added extension=imap.so to /etc/php.ini (at around line 600)

    6. Started in-built apache server on Leopard by doing this in a Terminal:

    sudo apachectl start

    6. Ran a phpinfo() and imap showed up in the list.

    7. Then did a little login to a Gmail account (which requires IMAP SSL).

    It worked.

    Hope this helps.

    I’m no expert, so please be careful if you try the above.

  9. Josh Says:

    Thanks a lot, worked like a charm. I already had a lot of struggle to get other dynamic PHP-Extensions working; this one worked on the first try! Good work!!

  10. Gabriel Says:

    Hi,

    What is the source directory of the imap extension? I stop here.

    Thanks, from Brazil! =)

  11. Sugar Developer Blog » Blog Archive » Enabling Xdebug under Mac OS X Leopard Says:

    [...] X Leopard, the pecl install xdebug command won’t work. The problem was earlier illustrated on this developer’s blog post, where the command line PHP version is built for 32-bit, while the [...]

  12. Albert Albala Says:

    Hi,

    I found that I had to cd php-5.2.6/ext/imap before running phpize, otherwise I get the error “phpize Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module”.

    I don’t know much about computers, but a google search suggests that you must be inside the source code directory before attempting phpize.

    Thanks for the great tutorial!

    Albert.

  13. Enabling Xdebug under Mac OS X Leopard | CRM Solution | CRM Software | Free CRM | Mobile CRM | Sugar CRM Says:

    [...] X Leopard, the pecl install xdebug command won’t work. The problem was earlier illustrated on this developer’s blog post, where the command line PHP version is built for 32-bit, while the [...]

Leave a Reply

Have feedback for us? Drop us a line.
Terms & Conditions | Privacy | Trademark Info | Contact Info | FAQs | SugarCRM Inc.© 2004 - 2009 All rights reserved.