..a dose of zero-day know-hows ..

Showing posts with label c-client libraries. Show all posts
Showing posts with label c-client libraries. Show all posts

11/25/2006

Headaches compiling PHP with IMAP [and Solution]

Backgrounder on IMAP:

IMAP or Internet Message Access Protocol is a protocol for accessing email from an IMAP server for online/offline/disconnected operations. This protocol was developed 20 yrs ago at Stanford University. One of the current active implementation with rewritten c-library is maintained under the supervison of the University of Washington. The latest IMAP - although its name might not sound to imply - also support POP protocol. A few open source applications for email management like SquirrelMail and IMP rely on IMAP in conjunction with PHP.

Backgrounder on PHP:

PHP or (Phils Homepage Tools)PHP Hypertext Preprocessor is an Open Source scripting language mainly used for web applications (although it can be used for desktop applications through its CLI, an example of a GUI implementation of PHP is PHP-GTK. PHP is server side, which means the processing is loaded to the server. Over the years the PHP Platform has proven its effectiveness, although still under debate :) , even some Java-based servers attempts to fully implement PHP because of its proven robustness (ex. Resin). One of the popular applications that run PHP is Mambo. SugarCRM, IMP, SquirrelMail implements PHP in conjunction with IMAP

The Problem:

I have encountered some problems getting PHP to compile with IMAP. For some reason my Apache died on 1st compile attempt of PHP with IMAP which caused one of the livesites I administer to be down. I tried different combinations of PHP 4.4.1, PHP 5.1.6, PHP 5.2.0 on IMAP-2004g, IMAP-2006c, IMAP-DEVEL. It was one nightmare i had to venture on. In the hope of easing someone not to go the same route I did. The whole trial and error costed me straight 25 hrs.

I have installed the 3 different versions of IMAP in the same way as outlined:
  1. Uncompressed the gzipped source tarball
  2. Inititated make using "make gso" (was on a Solaris 9)
  3. Made 2 symlinks pointing to the c-client libraries directory as "lib" and "include"
The following Combinations failed on me with errors message: Error Compiling PHP: conflicting types for 'utf8_mime2text'
  • PHP 4.4.1 + imap-2006d.DEV.SNAP-0611062033
  • PHP 5.1.6 + imap-2006d.DEV.SNAP-0611062033
  • PHP 5.2.0 + imap-2006d.DEV.SNAP-0611062033
  • PHP 4.4.1 + imap-2006c1
  • PHP 5.1.6 + imap-2006c1
The following Combinations failed on me with errors message: php_imap.c:(.text+0x2260): undefined reference to `mail_expunge'
  • PHP 4.4.1 + imap-2004g
  • PHP 5.1.6 + imap-2004g
  • PHP 5.2.0 + imap-2004g
So with the above errors, i speculated that the c-client libraries arent compiled to be sharable so i did additional steps to make them shared:
  1. cd c-client - Changed directory to c-client inside the extracted IMAP
  2. edited MakeFile to include: BASECFLAGS="-fPIC -O3" specifically on the GSO line for Solaris
  3. mkdir shared - Made a temporary directory
  4. cd shared - Changed directory to the temporary directory
  5. ar xv ../c-client.a - Extracted the *.o files
  6. gcc -shared -o c-client.so *.o - Derive a shared c-client..so from the *.o files
  7. cp c-client.so /usr/local/imap/imap2006c1/c-client libclient.so -Thanks to Ben for the correction
  8. hide libc-client.a (by adding "." before the name")
  9. cd ..
  10. ln -sf c-client include
  11. ln -sf c-client lib
The above 11 steps helped but wasnt put into real action until i finally figured out the correct combination. It was PHP 5.2.0 and IMAP-2006c1. IMAP was installed normally with the c-client.so (libc-client.so) made shareable. PHP was compiled as follows:

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --enable-mbstring --with-gd --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/local/lib --with-zlib --with-curl --with-pgsql=/usr/local/pgsql --with-gettext --with-ncurses --with-imap=/usr/local/imap/imap-2006c1/ --with-imap-ssl=/usr/local/ssl/