Internet message access protocol (IMAP) is one of the two most prevalent Internet standard protocols for e-mail retrieval.
This shows you how to enable IMAP extension in PHP.
First, grab the latest c-client library from this website.
ftp://ftp.cac.washington.edu/imap/
In this example, I’m using imap-2007f.tar.gz.
Copy the source to a directory, e.g. /usr/local/
cp imap-2007f.tar.gz /usr/local/ cd /usr/local/ tar zxf imap-2007f.tar.gz cd /usr/local/imap-2007f/
Open up the Makefile, find the port name for your system. I’m using RedHat Enterprise 5, so the port will be lr5. Once you have the port name, you can compile it.
You will have to create additional directories named lib/ and include/. From the c-client directory from your IMAP source tree, copy all the *.h files into include/ and all the *.c files into lib/. Additionally when you compiled IMAP, a file named c-client.a was created. Also put this in the lib/ directory but rename it as libc-client.a.
cd /usr/local/imap-2007f/ make lr5 mkdir lib mkdir include cp c-client/*.c lib/ cp c-client/*.h include/ cp c-client/c-client.a lib/libc-client.a
So, now, you are done with the compiling of c-client library. You have to compile PHP to enable IMAP support.
I’m using PHP 5.3.3 and the source is in /usr/local/src/php-5.3.3/
If you have compiled PHP before, you have to remove “config.cache” and “make clean”, otherwise skip this step and go to the next.
cd /usr/local/src/php-5.3.3/ rm config.cache make clean
To compile PHP with IMAP ( + SSL ) Support, modify the configure command to include –with-imap=/usr/local/imap-2007f and –with-imap-ssl
cd /usr/local/src/php-5.3.3/ ./configure … --with-imap=/usr/local/imap-2007f --with-imap-ssl
Next, make and make install
make make install
If you encounter the following similar error during make, read on, otherwise stop and start your Apache server and you are good to go.
can not be used when making a shared object; recompile with –fPIC
/usr/local/imap-2007f/lib/libc-client.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1
To fix the above error, you would have to re-compile the IMAP c-client library with -fPIC and re-compile PHP again.
cd /usr/local/imap-2007f/ make lr5 EXTRACFLAGS=-fPIC mkdir lib mkdir include cp c-client/*.c lib/ cp c-client/*.h include/ cp c-client/c-client.a lib/libc-client.a
That’s all. Have fun!. If you have any questions, please post in the comment.