Using imap functions in PHP without rebuilding and reinstalling
Asked Answered
A

1

5

I wanted the latest PHP version to work with on a fresh Macbook, but the php installation does not include imap functions by default. There is one specific function I need - namely the "imap_rfc822_parse_headers" function, but I don't feel like recompiling, building and installing PHP (not to mention the effort it takes to install c-client and imap.so beforehand) just for that. I fear that the convoluted procedures (of which each that I've found is somewhat different) might mess up my current installation which was by no means easy to set up.

Is there any other, easier way of installing imap into PHP? On a related note, is there perhaps a class-based alternative to the function I need?

Accountancy answered 22/6, 2012 at 14:27 Comment(0)
A
11

I've finally found the solution. Most of it was here: http://www.september28.co.uk/blog/2011/11/24/php-imap-support-in-mac-os-x-lion-without-recompiling-php/

My machine is a late 2011 Macbook Pro with MacOSX 10.7.4, PHP 5.4. installed via these instructions: http://www.hirmet.com/mac-os-x-lion-upgrade-to-php-5-4

Here's a step-by-step for those with a similar or identical setup:

Download the imap source from this url, focus on the one with the most recent date which doesn't end in "Z": ftp://ftp.cac.washington.edu/imap/

Unarchive, go into folder, run the following commands:

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

The above command will throw a bunch of warnings at you, but should complete sucessfully, unlike the command originally suggested in the september28 blog post.

Next, do the following:

$ 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

Once this is done, go into the downloaded php source folder if you made a custom upgrade like I did (as per the second link in the answer) and build the imap.so extension for your system. If you didn't build a custom version, just download the PHP source for the version you have installed, and use that, it doesn't matter.

$ cd ~/Downloads/Php-5.4.4/ext/imap
$ phpize
$ ./configure --with-imap==/usr/local/imap-2007 --with-kerberos --with-imap-ssl
$ make

Once done, do the following:

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

...or if your PHP extension folder is different, put that (you can see the location in phpinfo(); )

Restart apache and you should be ready to go.

$ sudo apachectl restart
Accountancy answered 22/6, 2012 at 15:7 Comment(6)
When I try to do: make osx EXTRACFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" on my OS X Mountain Lion, I get this error: -bash: $: command not found What should I do to proceed forward?Pique
omit the $ from every command you type, that's just the bash input symbol.Accountancy
I had to do an extra step, in my php.ini I had to add the extension manually. $ sudo nano php.ini -> search for Dynamic Extensions -> add extension="/usr/lib/php/extensions/no-debug-non-zts-20100525/imap.so" -> save and exit -> restart apache againNonmetal
jolyonruss, words cannot express how grateful I am to read this comment. You saved my life.Truncheon
FYI that "hirmet.com" link now leads to some kind of redirect hijack which is full of malware ads and who knows what.Laager
I found this one very helpful coz I couldn't compile php with imap due to some errors. Thanks a lot. :)Croteau

© 2022 - 2024 — McMap. All rights reserved.