Compile php_imap and mssql for PHP on Mac

IMAP

To get imap support in PHP on your Mac, you need to get the php_imap module compiled for your version of PHP. I have attached mine to this to save you the effort, but this wiki article can remain for reference.

Firstly, you need to download the Client-c code. This is a library that allows various applications to communicate with IMAP servers. PHP being one of them.

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

Save it into your downloads folder, and once finished, extract it. If you are using Terminal, you can do the above with the following commands: (NB, do all this in sudo)

cd ~/Downloads
curl -o imap.tar.gz ftp://ftp.cac.washington.edu/imap/imap-2007e.tar.gz
tar -zxvf imap.tar.gz

Then we need to compile it, and copy all the C files to the right places.

cd imap-2007e/
make osx EXTRACFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
mkdir /usr/local/include
cp c-client/*.h /usr/local/include/
mkdir /usr/local/lib
cp c-client/*.c /usr/local/lib/
cp c-client/c-client.a /usr/local/lib/libc-client.a

Now we need the version of PHP we need. To find out what version you are running, run this in a Terminal window:

php -v

That’ll tell you which version you need. Replace the curl address below with the relavant version from the php.net website.

cd ~/Downloads
curl -o php.tar.gz http://uk.php.net/distributions/php-x-x-x.tar.gz
tar -zxvf php.tar.gz

Once that is all extracted, we need to compile PHP:

cd php-x.x.x/
sudo ./configure
sudo make

Once that’s done we can go to the imap extension folder and compile that extension. There are more extensions in the file structure, but for now, we just need the imap one:

cd php-x.x.x/ext/imap
phpize
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/
MACOSX_DEPLOYMENT_TARGET=10.6

That should create a nice little imap.so file in the modules folder:

/Users/chris/Downloads/php-x.x.x/ext/imap/modules/imap.so

This file needs copying to the extensions folder on your PC. So you need to find the right folder. Mine was:

/usr/lib/php/extensions/no-debug-non-zts-20090626/

So, I copied the file there:

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

And then all we need to do is edit the php.ini file, to load the extension:

nano /etc/php.ini

Scroll down to the extensions bit, and add it in, mine would be like:

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

Then reboot Apache

apachectl restart

That should be it.

Next, php_mssql (if required)

MSSQL

The process is really very similar to what we just did for imap, but we do need to install freetds which is a mssql thing

Create the directory /usr/local/freetds
Download the latest version of freetds (http://www.freetds.org/software.html)
Open a terminal window
Untar/zip the freetds file and cd into that directory in terminal

Run the following to compile the extension

 ./configure --prefix=/usr/local/freetds --sysconfdir=/usr/local/freetds/conf/freetds --disable-libiconv --disable-odbc
make
sudo make install

Find the PHP source code from earlier, and go to the correct folder:

cd /Users/chris/Downloads/php-x.x.x./ext/mssql/
sudo phpize
sudo ./configure --with-mssql=/usr/local/freetds
sudo make

Now its the same as the imap section. Find the mssql.so file in the ext/mssql/modules/mssql.so and copy it to the extensions folder.

cp mssql.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

And then all we need to do is edit the php.ini file, to load the extension:

nano /etc/php.ini

Scroll down to the extensions bit, and add it in, mine would be like:

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

Then reboot Apache

apachectl restart

And that should work now. Create a page with a simple echo phpinfo() and that should confirm the fact.

11 comments on “Compile php_imap and mssql for PHP on Mac

  1. Mike October 22, 2014 9:42 pm

    Trying to get iMap support on my OS X Yosemite machine is driving me crazy. Using these instructions has me closer than anything else I’ve tried, but this command:
    ./configure –with-imap=/usr/local/imap-2007 –with-kerberos –with-imap-ssl=/usr/
    is giving the following error:
    configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

    Any ideas?

    Thanks!

    • admin October 22, 2014 9:50 pm

      Afraid I use a Linux vagrant VM for my development so I’ve not had to worry about this for some time. I’ve also not taken the leap to Yosemite yet. I find that it’s wise to wait a few weeks after release!

      I’ll have a look for you tomorrow though. Have you checked the log? What’s in there?

      • Mike October 23, 2014 1:58 pm

        PHP isn’t really an area of expertise for me. Nor are the different commands I’ve been running in Terminal to try to get this to work – I’m just copying commands I find on the web! That being the case, the log didn’t help me much. Here are the log contents:

        This file contains any messages produced by compilers while
        running configure, to aid debugging if configure makes a mistake.

        It was created by configure, which was
        generated by GNU Autoconf 2.69. Invocation command line was

        $ ./configure –with-imap=/usr/local/imap-2007 –with-kerberos –with-imap-ssl=/usr/

        ## ——— ##
        ## Platform. ##
        ## ——— ##

        hostname = Michaels-MBP
        uname -m = x86_64
        uname -r = 14.0.0
        uname -s = Darwin
        uname -v = Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64

        /usr/bin/uname -p = i386
        /bin/uname -X = unknown

        /bin/arch = unknown
        /usr/bin/arch -k = unknown
        /usr/convex/getsysinfo = unknown
        /usr/bin/hostinfo = Mach kernel version:
        Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64
        Kernel configured for up to 4 processors.
        2 processors are physically available.
        4 processors are logically available.
        Processor type: i486 (Intel 80486)
        Processors active: 0 1 2 3
        Primary memory available: 8.00 gigabytes
        Default processor set: 255 tasks, 1381 threads, 4 processors
        Load average: 1.96, Mach factor: 2.03
        /bin/machine = unknown
        /usr/bin/oslevel = unknown
        /bin/universe = unknown

        PATH: /usr/local/bin
        PATH: /usr/bin
        PATH: /bin
        PATH: /usr/sbin
        PATH: /sbin
        PATH: /usr/local/git/bin
        PATH: ANT_HOME/bin

        ## ———– ##
        ## Core tests. ##
        ## ———– ##

        configure:2301: checking for grep that handles long lines and -e
        configure:2359: result: /usr/bin/grep
        configure:2364: checking for egrep
        configure:2426: result: /usr/bin/grep -E
        configure:2431: checking for a sed that does not truncate output
        configure:2485: result: /usr/bin/sed
        configure:2617: checking for cc
        configure:2633: found /usr/bin/cc
        configure:2644: result: cc
        configure:2675: checking for C compiler version
        configure:2684: cc –version >&5
        Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
        Target: x86_64-apple-darwin14.0.0
        Thread model: posix
        configure:2695: $? = 0
        configure:2684: cc -v >&5
        Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
        Target: x86_64-apple-darwin14.0.0
        Thread model: posix
        configure:2695: $? = 0
        configure:2684: cc -V >&5
        clang: error: argument to ‘-V’ is missing (expected 1 value)
        clang: error: no input files
        configure:2695: $? = 1
        configure:2684: cc -qversion >&5
        clang: error: unknown argument: ‘-qversion’
        clang: error: no input files
        configure:2695: $? = 1
        configure:2715: checking whether the C compiler works
        configure:2737: cc conftest.c >&5
        configure:2741: $? = 0
        configure:2789: result: yes
        configure:2792: checking for C compiler default output file name
        configure:2794: result: a.out
        configure:2800: checking for suffix of executables
        configure:2807: cc -o conftest conftest.c >&5
        configure:2811: $? = 0
        configure:2833: result:
        configure:2855: checking whether we are cross compiling
        configure:2863: cc -o conftest conftest.c >&5
        configure:2867: $? = 0
        configure:2874: ./conftest
        configure:2878: $? = 0
        configure:2893: result: no
        configure:2898: checking for suffix of object files
        configure:2920: cc -c conftest.c >&5
        configure:2924: $? = 0
        configure:2945: result: o
        configure:2949: checking whether we are using the GNU C compiler
        configure:2968: cc -c conftest.c >&5
        configure:2968: $? = 0
        configure:2977: result: yes
        configure:2986: checking whether cc accepts -g
        configure:3006: cc -c -g conftest.c >&5
        configure:3006: $? = 0
        configure:3047: result: yes
        configure:3064: checking for cc option to accept ISO C89
        configure:3127: cc -c -g -O2 conftest.c >&5
        configure:3127: $? = 0
        configure:3140: result: none needed
        configure:3166: checking how to run the C preprocessor
        configure:3197: cc -E conftest.c
        configure:3197: $? = 0
        configure:3211: cc -E conftest.c
        conftest.c:9:10: fatal error: ‘ac_nonexistent.h’ file not found
        #include
        ^
        1 error generated.
        configure:3211: $? = 1
        configure: failed program was:
        | /* confdefs.h */
        | #define PACKAGE_NAME “”
        | #define PACKAGE_TARNAME “”
        | #define PACKAGE_VERSION “”
        | #define PACKAGE_STRING “”
        | #define PACKAGE_BUGREPORT “”
        | #define PACKAGE_URL “”
        | /* end confdefs.h. */
        | #include
        configure:3236: result: cc -E
        configure:3256: cc -E conftest.c
        configure:3256: $? = 0
        configure:3270: cc -E conftest.c
        conftest.c:9:10: fatal error: ‘ac_nonexistent.h’ file not found
        #include
        ^
        1 error generated.
        configure:3270: $? = 1
        configure: failed program was:
        | /* confdefs.h */
        | #define PACKAGE_NAME “”
        | #define PACKAGE_TARNAME “”
        | #define PACKAGE_VERSION “”
        | #define PACKAGE_STRING “”
        | #define PACKAGE_BUGREPORT “”
        | #define PACKAGE_URL “”
        | /* end confdefs.h. */
        | #include
        configure:3301: checking for icc
        configure:3310: result: no
        configure:3324: checking for suncc
        configure:3333: result: no
        configure:3351: checking whether cc understands -c and -o together
        configure:3379: cc -c conftest.c -o conftest2.o >&5
        configure:3383: $? = 0
        configure:3389: cc -c conftest.c -o conftest2.o >&5
        configure:3393: $? = 0
        configure:3448: result: yes
        configure:3462: checking for system library directory
        configure:3477: result: lib
        configure:3484: checking if compiler supports -R
        configure:3503: cc -o conftest -g -O2 conftest.c -R /usr/lib >&5
        clang: warning: argument unused during compilation: ‘-R’
        ld: can’t map file, errno=22 file ‘/usr/lib’ for architecture x86_64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        configure:3503: $? = 1
        configure: failed program was:
        | /* confdefs.h */
        | #define PACKAGE_NAME “”
        | #define PACKAGE_TARNAME “”
        | #define PACKAGE_VERSION “”
        | #define PACKAGE_STRING “”
        | #define PACKAGE_BUGREPORT “”
        | #define PACKAGE_URL “”
        | /* end confdefs.h. */
        |
        | int
        | main ()
        | {
        |
        | ;
        | return 0;
        | }
        configure:3513: result: no
        configure:3518: checking if compiler supports -Wl,-rpath,
        configure:3537: cc -o conftest -g -O2 conftest.c -Wl,-rpath,/usr/lib >&5
        configure:3537: $? = 0
        configure:3547: result: yes
        configure:3592: checking build system type
        configure:3606: result: x86_64-apple-darwin14.0.0
        configure:3626: checking host system type
        configure:3639: result: x86_64-apple-darwin14.0.0
        configure:3659: checking target system type
        configure:3672: result: x86_64-apple-darwin14.0.0
        configure:3775: checking for PHP prefix
        configure:3777: result: /usr
        configure:3779: checking for PHP includes
        configure:3781: result: -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
        configure:3783: checking for PHP extension directory
        configure:3785: result: /usr/lib/php/extensions/no-debug-non-zts-20121212
        configure:3787: checking for PHP installed headers prefix
        configure:3789: result: /usr/include/php
        configure:3792: checking if debug is enabled
        configure:3818: result: no
        configure:3821: checking if zts is enabled
        configure:3847: result: no
        configure:3918: checking for re2c
        configure:3948: result: no
        configure:3973: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
        configure:3987: checking for gawk
        configure:4018: result: no
        configure:3987: checking for nawk
        configure:4018: result: no
        configure:3987: checking for awk
        configure:4004: found /usr/bin/awk
        configure:4015: result: awk
        configure:4038: checking if awk is broken
        configure:4045: result: no
        configure:4070: checking for IMAP support
        configure:4110: result: yes, shared
        configure:4119: checking for IMAP Kerberos support
        configure:4134: result: yes
        configure:4143: checking for IMAP SSL support
        configure:4158: result: /usr/
        conftest.c:11:10: fatal error: ‘/mail.h’ file not found
        #include
        ^
        1 error generated.
        configure:4560: checking for utf8_mime2text signature
        configure:4582: cc -c -I conftest.c >&5
        clang: error: no input files
        configure:4582: $? = 1
        configure: failed program was:
        | /* confdefs.h */
        | #define PACKAGE_NAME “”
        | #define PACKAGE_TARNAME “”
        | #define PACKAGE_VERSION “”
        | #define PACKAGE_STRING “”
        | #define PACKAGE_BUGREPORT “”
        | #define PACKAGE_URL “”
        | #define COMPILE_DL_IMAP 1
        | #define HAVE_IMAP 1
        | /* end confdefs.h. */
        |
        | #include
        | #include
        |
        | int
        | main ()
        | {
        |
        | SIZEDTEXT *src, *dst;
        | utf8_mime2text(src, dst);
        |
        | ;
        | return 0;
        | }
        configure:4594: result: new
        configure:4605: checking for U8T_DECOMPOSE
        configure:4625: cc -c -I conftest.c >&5
        clang: error: no input files
        configure:4625: $? = 1
        configure: failed program was:
        | /* confdefs.h */
        | #define PACKAGE_NAME “”
        | #define PACKAGE_TARNAME “”
        | #define PACKAGE_VERSION “”
        | #define PACKAGE_STRING “”
        | #define PACKAGE_BUGREPORT “”
        | #define PACKAGE_URL “”
        | #define COMPILE_DL_IMAP 1
        | #define HAVE_IMAP 1
        | #define HAVE_NEW_MIME2TEXT 1
        | /* end confdefs.h. */
        |
        | #include
        |
        | int
        | main ()
        | {
        |
        | int i = U8T_CANONICAL;
        |
        | ;
        | return 0;
        | }
        configure:4637: result:
        configure:4642: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

        ## —————- ##
        ## Cache variables. ##
        ## —————- ##

        ac_cv_build=x86_64-apple-darwin14.0.0
        ac_cv_c_compiler_gnu=yes
        ac_cv_env_CC_set=
        ac_cv_env_CC_value=
        ac_cv_env_CFLAGS_set=
        ac_cv_env_CFLAGS_value=
        ac_cv_env_CPPFLAGS_set=
        ac_cv_env_CPPFLAGS_value=
        ac_cv_env_CPP_set=
        ac_cv_env_CPP_value=
        ac_cv_env_LDFLAGS_set=
        ac_cv_env_LDFLAGS_value=
        ac_cv_env_LIBS_set=
        ac_cv_env_LIBS_value=
        ac_cv_env_build_alias_set=
        ac_cv_env_build_alias_value=
        ac_cv_env_host_alias_set=
        ac_cv_env_host_alias_value=
        ac_cv_env_target_alias_set=
        ac_cv_env_target_alias_value=
        ac_cv_host=x86_64-apple-darwin14.0.0
        ac_cv_objext=o
        ac_cv_path_EGREP=’/usr/bin/grep -E’
        ac_cv_path_GREP=/usr/bin/grep
        ac_cv_prog_AWK=awk
        ac_cv_prog_CPP=’cc -E’
        ac_cv_prog_ac_ct_CC=cc
        ac_cv_prog_cc_c89=
        ac_cv_prog_cc_cc_c_o=yes
        ac_cv_prog_cc_g=yes
        ac_cv_target=x86_64-apple-darwin14.0.0
        ac_cv_u8t_decompose=no
        ac_cv_utf8_mime2text=new
        lt_cv_path_SED=/usr/bin/sed
        php_cv_cc_dashr=no
        php_cv_cc_rpath=yes

        ## —————– ##
        ## Output variables. ##
        ## —————– ##

        AR=”
        AWK=’awk’
        CC=’cc’
        CFLAGS=’-g -O2′
        CONFIGURE_COMMAND=’ ‘\”./configure’\” ‘\”–with-imap=/usr/local/imap-2007’\” ‘\”–with-kerberos’\” ‘\”–with-imap-ssl=/usr/’\”’
        CONFIGURE_OPTIONS=’ ‘\”–with-imap=/usr/local/imap-2007’\” ‘\”–with-kerberos’\” ‘\”–with-imap-ssl=/usr/’\”’
        CPP=’cc -E’
        CPPFLAGS=”
        DEFS=”
        DSYMUTIL=”
        ECHO=’/bin/echo’
        ECHO_C=’\c’
        ECHO_N=”
        ECHO_T=”
        EGREP=’/usr/bin/grep -E’
        EXEEXT=”
        GREP=’/usr/bin/grep’
        KRB5_CONFIG=”
        LDFLAGS=”
        LIBOBJS=”
        LIBS=”
        LIBTOOL=”
        LN_S=”
        LTLIBOBJS=”
        NMEDIT=”
        OBJEXT=’o’
        OPENSSL_INCDIR_OPT=”
        PACKAGE_BUGREPORT=”
        PACKAGE_NAME=”
        PACKAGE_STRING=”
        PACKAGE_TARNAME=”
        PACKAGE_URL=”
        PACKAGE_VERSION=”
        PATH_SEPARATOR=’:’
        PKG_CONFIG=”
        RANLIB=”
        RE2C=’exit 0;’
        SED=’/usr/bin/sed’
        SHELL=’/bin/sh’
        SHLIB_DL_SUFFIX_NAME=’so’
        SHLIB_SUFFIX_NAME=’dylib’
        STRIP=”
        ac_ct_CC=’cc’
        bindir=’${exec_prefix}/bin’
        build=’x86_64-apple-darwin14.0.0′
        build_alias=”
        build_cpu=’x86_64′
        build_os=’darwin14.0.0′
        build_vendor=’apple’
        datadir=’${datarootdir}’
        datarootdir=’${prefix}/share’
        docdir=’${datarootdir}/doc/${PACKAGE}’
        dvidir=’${docdir}’
        exec_prefix=’NONE’
        host=’x86_64-apple-darwin14.0.0′
        host_alias=’x86_64-apple-darwin14.0.0′
        host_cpu=’x86_64′
        host_os=’darwin14.0.0′
        host_vendor=’apple’
        htmldir=’${docdir}’
        includedir=’${prefix}/include’
        infodir=’${datarootdir}/info’
        libdir=’${exec_prefix}/lib’
        libexecdir=’${exec_prefix}/libexec’
        localedir=’${datarootdir}/locale’
        localstatedir=’${prefix}/var’
        mandir=’${datarootdir}/man’
        oldincludedir=’/usr/include’
        pdfdir=’${docdir}’
        prefix=’/usr’
        program_transform_name=’s,x,x,’
        psdir=’${docdir}’
        sbindir=’${exec_prefix}/sbin’
        sharedstatedir=’${prefix}/com’
        sysconfdir=’${prefix}/etc’
        target=’x86_64-apple-darwin14.0.0′
        target_alias=”
        target_cpu=’x86_64′
        target_os=’darwin14.0.0′
        target_vendor=’apple’

        ## ———– ##
        ## confdefs.h. ##
        ## ———– ##

        /* confdefs.h */
        #define PACKAGE_NAME “”
        #define PACKAGE_TARNAME “”
        #define PACKAGE_VERSION “”
        #define PACKAGE_STRING “”
        #define PACKAGE_BUGREPORT “”
        #define PACKAGE_URL “”
        #define COMPILE_DL_IMAP 1
        #define HAVE_IMAP 1
        #define HAVE_NEW_MIME2TEXT 1

        configure: exit 1

        Thanks.

        • admin October 23, 2014 2:06 pm

          Did you use to have homebrew (http://brew.sh/) installed on your Mac? Perhaps Yosemite removed it? Try installing it again, and then install php with:

          brew install php55 --with-fpm --with-imap --without-apache --with-debug

          • Mike October 23, 2014 3:09 pm

            I don’t know anything about homebrew but I do recall a proposed fix yesterday that called for it and it wasn’t found on my Mac. I installed it using the link you provided and ran ‘brew install…’ but it displayed an error:
            Error: No available formula for php55

          • admin October 23, 2014 3:14 pm

            Try php56, sorry not tried it for a while

          • Mike October 23, 2014 3:40 pm

            Still not working. Thanks very much for your help, but I give up. Getting much too old for this s***.

  2. admin October 27, 2014 1:09 pm

    This is the main reason I switched to using a Vagrant headless VM for development work. Linux is so much easier to install the necessary PHP extensions I require. I would suggest you take a look if you are into development. http://www.vagrantup.com

  3. Camilo December 23, 2014 9:42 am

    Thanks for this old but still useful guide, with just some minor adjustments, it worked perfectly for Mac OS Yosemite!

    I knew there was a new version of the imap library, so I downloaded version 2007f instead of 2007e. You also forgot to make after configure so that the .so file is created.

    Greetings.

    • admin January 13, 2015 9:08 pm

      Pretty sure it states to do a make… But thanks anyway

    • Norberto lodela June 22, 2015 9:28 pm

      Camilo, please share what minor adjustments you did… I’m trying to install IMAP on my Yosemite, PHP v- 5.5.14 but at some point, I got stuck… mainly when we have to relocate the “.so” file to the extensions… simply I cant find it… please help!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>