Enabling IMAP support under OS X Leopard
26 Aug, 2008Posted 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().

August 27th, 2008 at 5:52 am
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. :-/
August 28th, 2008 at 4:34 am
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.
September 3rd, 2008 at 10:59 am
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?
September 5th, 2008 at 6:53 am
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.
September 9th, 2008 at 9:23 pm
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)
September 18th, 2008 at 3:54 am
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
September 28th, 2008 at 6:51 am
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
October 12th, 2008 at 9:10 am
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.
October 21st, 2008 at 11:38 am
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!!
November 19th, 2008 at 5:28 am
Hi,
What is the source directory of the imap extension? I stop here.
Thanks, from Brazil! =)
November 25th, 2008 at 2:22 pm
[...] 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 [...]
December 17th, 2008 at 8:29 am
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.
February 6th, 2009 at 9:04 pm
[...] 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 [...]
September 11th, 2009 at 1:57 am
After upgrading to Snow Leopard i found that Imap stopped working as a newer version of php was installed (5.3). I followed the steps in the main article but as it would not compile with a ‘cc cannot create an executable’ error i changed
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
to
MACOSX_DEPLOYMENT_TARGET=10.6 \
CFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” \
CCFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” \
CXXFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” \
LDFLAGS=”-arch i386 -arch x86_64 -bind_at_load” \
./configure –with-kerberos –with-imap-ssl
leaving out the power pc libs as Snow Leopard doesnt have them. Also check after the upgrade that you have renamed or backed up and renamed php.ini.default to php.ini with the extension=imap.so added and the extension_dir commented out.
December 7th, 2009 at 3:00 am
HI john / All
I have MAC OS X 10.5.8 PPC 64 bit
PHP version = 5.2.8
i have follow below steps from this post.
$ sudo mkdir -p /SourceCache
$ cd /SourceCache
$ 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\
$ 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
$ sudo curl -O http://www.opensource.apple.com/source/apache_mod_php/apache_mod_php-44.2/php-5.2.8.tar.bz2
$ tar -xjvf php-5.2.8.tar.bz2
$ cd /SourceCache/php-5.2.8/ext/imap
$ phpize
$ 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
$ make
$ sudo make install
$ sudo echo \extension=imap.so\ >> /etc/php.ini
$ cp /SourceCache/php-5.2.8/ext/imap/modules/imap.so /usr/lib/php/extensions/no-debug-non-zts-20060613
$ sudo apachectl restart
countinue in next post
December 7th, 2009 at 3:04 am
now my issue is while my check from command line, it’s gives warning as below. and imap extension not seems loaded.
$ php -m
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/imap.so’ – (null) in Unknown on line 0
[PHP Modules]
ctype
curl
date
dom
exif
filter
ftp
hash
iconv
json
………. output omitted…..
zlib
[Zend Modules]
But i have check through info.php, it shows it loaded.
i m much confused between this. it will be really apprentice if you can take me out of this.
Thanks & Rg.
Shailesh
December 7th, 2009 at 3:05 am
HI john / All
I have MAC OS X 10.5.8 PPC 64 bit
PHP version = 5.2.8
i have follow below steps from this post.
$ sudo mkdir -p /SourceCache
$ cd /SourceCache
$ 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”
$ 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
$ sudo curl -O http://www.opensource.apple.com/source/apache_mod_php/apache_mod_php-44.2/php-5.2.8.tar.bz2
$ tar -xjvf php-5.2.8.tar.bz2
$ cd /SourceCache/php-5.2.8/ext/imap
$ phpize
$ 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
$ make
$ sudo make install
$ sudo echo “extension=imap.so” >> /etc/php.ini
$ cp /SourceCache/php-5.2.8/ext/imap/modules/imap.so /usr/lib/php/extensions/no-debug-non-zts-20060613
$ sudo apachectl restart
now my issue is while my check from command line, it’s gives warning as below. and imap extension not seems loaded.
$ php -m
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/imap.so’ – (null) in Unknown on line 0
[PHP Modules]
ctype
curl
date
dom
exif
filter
ftp
hash
iconv
json
ldap
libxml
mbstring
mysql
mysqli
odbc
openssl
pcre
PDO
pdo_sqlite
posix
Reflection
session
SimpleXML
sockets
SPL
SQLite
standard
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zlib
[Zend Modules]
But i have check through info.php, it shows it loaded.
i m much confused between this. it will be really apprentice if you can take me out of this.
Thanks & Rg.
Shailesh
February 1st, 2010 at 11:47 am
Will re-building PHP with the above flags remove my existing PHP extensions, like GD?