Enable IMAP PHP module on OSX Snow Leopard Server 10.6

avatar specialopssecurity Pro Apr 5. 2010. 1:03 pm
[UPDATED 09-JUL-2011 with edits from emil_l]
____________________________________________________________________

Snow Leopard Server has PHP 5.3 built-in (hooray!), but without the IMAP module (drat!). There are several guides out there that have partial solutions to the problem, but most ask you to build your own Apache and PHP apart from the OSX native. I wanted to use as much native OSX as possible. One blog in particular was the easiest solution (with a few minor corrections in the blog comments). Here are all the instructions, in order, with all the corrections inline:

____________________________________________________________________

1. Open a Terminal session from OSX
____________________________________________________________________

2. Download and unpack the latest IMAP source code (2007e as of this writing):

cd ~/Downloads

curl -o imap.tar.gz ftp://ftp.cac.washington.edu/imap/imap-2007e.tar.gz

tar -zxvf imap.tar.gz
____________________________________________________________________

3. Build IMAP libraries and copy to correct locations:

cd imap-2007e/

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

sudo mkdir /usr/local/include

sudo cp c-client/*.h /usr/local/include/

sudo mkdir /usr/local/lib

sudo cp c-client/*.c /usr/local/lib/

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

4. Download and unpack the latest PHP source code (5.3.1 as of this writing):

cd ~/Downloads

curl -o php.tar.gz http://us.php.net/distributions/php-5.3.1.tar.gz

tar -zxvf php.tar.gz
____________________________________________________________________

5. We only need the source for the IMAP extension, so there's no need to compile all of PHP. Please note that there are double-hyphens in front of each "with" and single hyphens elsewhere (difficult to read with this font):

cd php-5.3.1/ext/imap

make clean

phpize

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-imap=/usr/local/imap-2007 --with-kerberos --with-imap-ssl=/usr/
____________________________________________________________________

6. If you received errors (specifically, a complaint about OpenSSL's evp.h), you may need to adjust the path at the end of "with-imap-ssl" to /usr/include or /usr/include/openssl. The above worked for me, using Snow Leopard 10.6.3.
____________________________________________________________________

7. Now make the module:

make
____________________________________________________________________

8. If you didn't receive an error, go to the next step. If you received an error about pcre.h (notably on MAMP instead of Snow Leopard Server), you need to copy some files from the downloaded PHP source

sudo cp ../pcre/pcrelib/pcre.h /usr/include/php/ext/pcre/

make
____________________________________________________________________

9. And now we copy it into our extensions directory. Your directory might be named differently (the numbers at the end correspond to June 26, 2009), so if you don't have this exact directory, look for the subdirectory of /usr/lib/php/extensions that has the most recent creation date:

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

10. Now we edit the php.ini to reference our new imap.so extension:

sudo nano /etc/php.ini
____________________________________________________________________

11. Find the section where there are other "extension=" commands (there should be 30-50 of them). The ones that end with ".dll" can be removed -- they only apply to Windows and just clutter up your file.
____________________________________________________________________

12. At the end of all the extension= statements, add the following:

extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/imap.so
____________________________________________________________________

13. DOUBLE-CHECK: if you had a different directory on your system (that didn't end with 20090626) adjust accordingly.
____________________________________________________________________

14. TRIPLE-CHECK: make absolutely sure there is NOT a semi-colon in front of the word "extension". This ; character means to ignore the whole line. Remove the semi-colon if it is present.
____________________________________________________________________

15. As long as you're in PHP.INI, you may want to adjust other options, such as memory allowed for PHP and file upload sizes. This step is optional:

memory_limit=128M
post_max_size=200M
upload_max_filesize=200M
____________________________________________________________________

16. When you are finished editing, press CTRL-X to exit. You will be prompted if you would like to save. Enter Y for Yes. Now we just need to restart Apache:

sudo apachectl graceful
____________________________________________________________________
____________________________________________________________________

All done! If you would rather just cheat, I've attached the imap.so that I built to this posting (click below) and you can drop it into your extensions directory.
avatar Ilija Studen Staff Apr 5. 2010. 3:18 pm
Hello,

Thanks for sharing this info! There are certainly people who will find this information useful.
avatar johnk Apr 19. 2010. 11:04 am
Thanks for the info. I went through this entire tutorial, I am completely un-versed in terminal, dabbled a couple lines here and there, but anyway I performed all of these steps. I am currently installing activecollab and I am getting the message in my environment test:

warning — Extension 'imap' was not found. This extension is used for connect to POP3/IMAP mailboxes and read email messages

Any idea why I am getting this message? If I performed these steps successfully I am assuming imap is enabled and operating. Any help is appreciated. Thank you very much!

-J
avatar Ilija Studen Staff Apr 19. 2010. 11:06 am
Have you restarted Apache?

If extension was successfully installed and Apache restarted, activeCollab installer should be able to detect it and skip that warning.
avatar johnk Apr 19. 2010. 11:14 am
I entered the command of sudo apachetcl graceful, entered my pw, I also stopped and restarted web services but still get the warning message in the browser.
avatar specialopssecurity Pro Apr 19. 2010. 11:43 am
[deleted -- updated post #1 above]
avatar johnk Apr 19. 2010. 11:53 am
extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20090626 => /usr/lib/php/extensions/no-debug-non-zts-20090626


Yeah I checked that at that step, it actually came up when I did a go to folder search. I have two folders within the extension, the one above, and one that is 20060613. Within the 20090626 I have the files of:
imap.so
phpcups.so
proxyauth.so
avatar specialopssecurity Pro Apr 19. 2010. 12:02 pm
[deleted -- updated post #1 above]
avatar johnk Apr 19. 2010. 12:58 pm
Hmm, I checked it out, they all seemed alright. I even added the "adminstrator" user I am currently logged in as with read/write access, restarted apache, and have the same error. This is what I currently get back in terminal. Once again thank you for the help.

drwxr-xr-x+ 5 root wheel 170 Apr 19 09:31 .
drwxr-xr-x 4 root wheel 136 Apr 9 17:42 ..
-rwxr-xr-x+ 1 root wheel 1177976 Apr 19 09:31 imap.so
-rwxr-xr-x+ 1 root wheel 76832 Jul 20 2009 phpcups.so
-rwxr-xr-x+ 1 root wheel 60208 Jul 20 2009 proxyauth.so
avatar johnk Apr 19. 2010. 1:14 pm
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_exif.dll
;extension=php_fileinfo.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11g Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_phar.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll
;extension=/usr/lib/php/extensions/no-debu-non-zts-20090626/imap.so


Hmm, well I noticed I forgot the "g" at the end of "debug", I added that, restarted apache, thought FOR SURE this was going to fix it, and still get the same warning.
or Go To Next Page

Try activeCollab free for 30 days, No credit card required!

Instant access to activeCollab, no installation needed.

.tryactivecollab.com

If you are already a user of activeCollab, you can log in here.