How to Compile PHP with IMAP Support

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.

In this example, I’m using imap-2007f.tar.gz.

Copy the source to a directory, e.g. /usr/local/

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.

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.

To compile PHP with IMAP ( + SSL ) Support, modify the configure command to include –with-imap=/usr/local/imap-2007f and –with-imap-ssl

Next, make and 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: *** [] 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.

That’s all. Have fun!. If you have any questions, please post in the comment.

You may also like

14 Response Comments

  • Muhammad Aftab  March 12, 2013 at 11:50 pm

    Hello, thanks for the tutorial. I followed all the steps and recompiled with -fPIC flag, but am still getting the following error during make:

    /usr/local/imap-2007f/lib/libc-client.a: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    make: *** [] Error 1

    I am trying to compile php-5.4.12 on Ubuntu 12.04 LTS with the following flags:

    ./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql –with-imap=/usr/local/imap-2007f –with-imap-ssl –with-openssl

    Thanks in advance for any suggestions.

  • Arun Ghosh  April 26, 2013 at 3:50 pm

    You can enter into the imap installtion directory and issue the following commands to fix the error,
    /usr/local/imap-2007f/lib/libc-client.a: could not read symbols: Bad value

    sed -i ‘s/SSLDIR=\/usr\/local\/ssl/SSLDIR=\/etc\/pki\/tls/g’ src/osdep/unix/Makefile

    sed -i ‘s/SSLINCLUDE=$(SSLDIR)\/include/SSLINCLUDE=\/usr\/include\/openssl/g’ src/osdep/unix/Makefile

    sed -i ‘s/SSLLIB=$(SSLDIR)\/lib/SSLLIB=\/usr\/lib\/openssl/g’ src/osdep/unix/Makefile

  • Arun Ghosh  April 26, 2013 at 3:56 pm

    If are using centos to install imap and you may use the following command to install imap,
    make slx

    It must apply the commands in the previous post to fix the error before making slx. If it is 64 bit you have to use EXTRACFLAGS=-fPIC parameter in make.

    make slx EXTRACFLAGS=-fPIC

  • WS Jin  March 8, 2014 at 2:23 pm

    I really appreciate your advice ‘How to Compile PHP with IMAP Support’. It is sure and reliable for related problem.Thank you very much!!

  • Rajib  October 10, 2015 at 10:58 pm

    Hi, I tried a lot from the step given here. But i am unable to get th Imap working. It worked once but then when I realsized I have not picked mysql, and compiled again, i lost it. I have no idea. what to do..

  • Bryce Morsello  November 3, 2015 at 10:50 pm

    Fantastic! I’ve been scouring blogs and notes all afternoon, and you’ve solved all my PHP and IMAP problems in one go!

  • Kevin  January 9, 2016 at 1:44 pm

    Thank you for your note re the libc-client.a: could not read symbols error.

    I struggled with the revised make lr5 EXTRACFLAGS=-fPIC as I’m not familiar with make and was building on FreeBSD.

    For amyone with a similar problem, you need to change ‘lr5′ to match your system. do a ‘more makefile’ to see a list of codes for your OS

  • ibon  April 4, 2016 at 5:32 pm

    Thanks! for those who need to compile major php versions in old systems this is really useful. It works like a charm. PD (Scenarios: SugarCE to SuiteCRM or Pro) ./configure -prefix=/usr/local -with-apxs2=/usr/bin/apxs2 -with-mysql=/usr -with-mysqli=/usr/bin/mysql_config -with-pgsql=/usr -with-tidy=/usr -with-curl=/usr/bin -with-curlwrappers -with-openssl=/usr -enable-mbstring -with-pdo-pgsql=/usr -with-pdo-mysql=/usr -with-xsl=/usr -with-ldap -with-xmlrpc -with-iconv-dir=/usr -with-snmp=/usr -enable-exif -enable-calendar -with-bz2=/usr -with-mcrypt=/usr -with-gd -with-jpeg-dir=/usr -with-png-dir=/usr -with-zlib-dir=/usr -with-freetype-dir=/usr -enable-mbstring -enable-zip -with-pear -enable-libxml -enable-soap -enable-sockets -enable-ssl -enable-ftp -with-imap=/usr/local/imap-2007f -with-imap-ssl -with-kerberos .

  • Frankieneilk  January 31, 2017 at 10:36 am

    Тайланд. Любые экскурсии с Паттайя. Встреча в аэропорту От тайской тур агентства Русалочка. Все описания экскурсий, цены и фотографии смотреть по ссылке Телефон в Тайланде (WhatsApp, Viber, Line, Telegram): +66–861559142

  • MichelEnary  February 13, 2017 at 1:46 pm

    Есть такая услуга – добровольное медицинское обслуживание .
    Она предполагает, что вы платите небольшую сумму за то, что посещает врачей в течение года бесплатно.
    Однако опросы показали, что лишь 6% жителей Санкт-Петербурга знают о ее существовании.
    Да потому что клиникам намного выгодней брать плату за каждый визит.
    А если какой-нибудь сотрудник клиники попытается рассказать про добровольное медицинское обслуживание клиенту – это сулит ему увольнением.
    Эта информация уже спровоцировала кучу скандалов, сразу после того как информацию об услуге рассекретил один врач.
    Его уволили , после того, как он посоветовал ДМО своему пациенту.
    Самое невероятное, что информация по ДМО присутствуют в открытом доступе, просто натыкались на эту информацию только случайные люди.
    Как отстоять свои права?
    О правилах оказания такой услуги и обязанностях клиник можно узнать, сделав запрос в Яндексе: “добровольное медицинское обслуживание”.
    Именно обслуживание, а не страхование.


  • James D  April 24, 2017 at 2:15 am

    had to add ‘–with-pic’ at the end of my php configure command, and -fPIC when making the imap files, but it worked….10 compiles later…
    your help was invaluable!!


Leave A Comment

Please enter your name. Please enter an valid email address. Please enter a message.