HOWTO: PHP with IMAP support for CentOS6

Maniak

Verified User
Joined
Aug 25, 2004
Messages
220
Location
Switzerland
I've pulled my hairs getting a proper working version of IMAP compiled within PHP. The trick was to compile the extension without issues. I wanted to get the latest version of IMAP.

As such the way to go on CentOS 6.3 x86_64 (64 bits) was:

Prepare the OS

Code:
yum install -y pam-devel libc-client libc-client-devel
Install IMAP from source

Code:
wget ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz
tar -zxvf imap-2007f.tar.gz
cd imap-2007*
make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd IP6=4
echo "set disable-plaintext nil" > /etc/c-client.cf
mkdir /usr/local/imap-2007f
mkdir /usr/local/imap-2007f/include/
mkdir /usr/local/imap-2007f/lib/
chmod -R 077 /usr/local/imap-2007f
rm -rf /usr/local/imap-2007f/include/*
rm -rf /usr/local/imap-2007f/lib/*
cp imapd/imapd /usr/sbin/
cp c-client/*.h /usr/local/imap-2007f/include/
cp c-client/*.c /usr/local/imap-2007f/lib/
cp c-client/c-client.a /usr/local/imap-2007f/lib/libc-client.a
and then add to /usr/local/directadmin/custombuild/custom/{ap1,ap2,suphp}/configure.phpX (where X is the version of PHP and either ap1, ap2 or suphp).

Code:
--with-imap-ssl=/usr/local/imap-2007f \
--with-imap=/usr/local/imap-2007f \
Hope this will help

Credits: http://forum.eltechsupport.com/directadmin/error-while-enabling-imap-php-module-directadmin-server/
 
Last edited:

SeLLeRoNe

Super Moderator
Joined
Oct 9, 2004
Messages
6,793
Location
A Coruña, Spain
I was testing this how-to but apparently it doesnt work on my box.

PHP fail on compile with this error:

Code:
/usr/bin/ld: /usr/local/imap-2007f/lib/libc-client.a(osdep.o): relocation R_X86_64_32 against `server_input_wait' 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
make: *** Waiting for unfinished jobs....
/usr/local/imap-2007f/lib/libc-client.a(osdep.o): In function `ssl_onceonlyinit':
/usr/local/crazynetwork/imap-2007f/c-client/osdep.c:337: warning: the use of `tmpnam' is dangerous, better use `mkstemp'
Any hint?

Regards
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,789
Location
LT, EU
Give it a try (place the code in "setup-imap.sh" and execute it then):
Code:
#!/bin/sh
# Script for PHP-IMAP installation. 0.1b
# Written by Martynas Bendorius (smtalk)

CWD=`pwd`
OS=`uname`

#Is it a 64-bit OS?
B64=0
    
B64COUNT=`uname -m | grep -c 64`
if [ "$B64COUNT" -eq 1 ]; then
    B64=1
    LD_LIBRARY_PATH=/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
    export LD_LIBRARY_PATH
fi

if [ ! -e /usr/include/krb5.h ] && [ -e /etc/redhat-release ]; then
    echo "Installing krb5-devel"
    yum -y install krb5-devel
fi

VERSION=2006k
URL="ftp://ftp.cac.washington.edu/imap/old/imap-${VERSION}.tar.Z"
FILENAME=imap-${VERSION}
TARBALL=${FILENAME}.tar.Z

echo "Downloading ${TARBALL}..."
wget -O ${TARBALL} ${URL}
tar xzf ${TARBALL}
cd ${FILENAME}

echo "Installing ${FILENAME}..."

if [ ${OS} = "FreeBSD" ]; then
    if [ ${B64} -eq 0 ]; then
        make bsf
    else
        make bsf EXTRACFLAGS=-fPIC
    fi
else
    perl -pi -e 's#SSLDIR=/usr/local/ssl#SSLDIR=/etc/pki/tls#' src/osdep/unix/Makefile
    perl -pi -e 's#SSLINCLUDE=\$\(SSLDIR\)/include#SSLINCLUDE=/usr/include/openssl#' src/osdep/unix/Makefile
    perl -pi -e 's#SSLLIB=\$\(SSLDIR\)/lib#SSLLIB=/usr/lib/openssl#' src/osdep/unix/Makefile
    if [ ${B64} -eq 0 ]; then
        make slx
    else
        make slx EXTRACFLAGS=-fPIC
    fi
fi

echo "Copying files to /usr/local/php-imap"
mkdir -p /usr/local/php-imap/include
mkdir -p /usr/local/php-imap/lib
chmod -R 077 /usr/local/php-imap
cp -f c-client/*.h /usr/local/php-imap/include/
cp -f c-client/*.c /usr/local/php-imap/lib/
cp -f c-client/c-client.a /usr/local/php-imap/lib/libc-client.a
cd ..
rm -rf ${FILENAME}

if [ -d /usr/lib/x86_64-linux-gnu ] && [ ! -d /usr/kerberos/lib ]; then
    mkdir -p /usr/kerberos
    ln -s /usr/lib/x86_64-linux-gnu /usr/kerberos/lib
fi


exit 0;
Run the script, then add to configure.php*:
Code:
--with-imap=/usr/local/php-imap \
--with-imap-ssl \
And rebuild PHP.
 
Last edited:

jca

Verified User
Joined
Oct 31, 2006
Messages
237
Location
Allen, TX
As always and expected, Martynas, your solution worked great!

Give it a try:
Code:
#!/bin/sh
# Script for PHP-IMAP installation. 0.1b
# Written by Martynas Bendorius (smtalk)

CWD=`pwd`
OS=`uname`

#Is it a 64-bit OS?
B64=0
	
B64COUNT=`uname -m | grep -c 64`
if [ "$B64COUNT" -eq 1 ]; then
	B64=1
	LD_LIBRARY_PATH=/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
	export LD_LIBRARY_PATH
fi

if [ ! -e /usr/include/krb5.h ] && [ -e /etc/redhat-release ]; then
	echo "Installing krb5-devel"
	yum -y install krb5-devel
fi

VERSION=2006k
URL="ftp://ftp.cac.washington.edu/imap/old/imap-${VERSION}.tar.Z"
FILENAME=imap-${VERSION}
TARBALL=${FILENAME}.tar.Z

echo "Downloading ${TARBALL}..."
wget -O ${TARBALL} ${URL}
tar xzf ${TARBALL}
cd ${FILENAME}

echo "Installing ${FILENAME}..."

if [ ${OS} = "FreeBSD" ]; then
	if [ ${B64} -eq 0 ]; then
		make bsf
	else
		make bsf EXTRACFLAGS=-fPIC
	fi
else
	perl -pi -e 's#SSLDIR=/usr/local/ssl#SSLDIR=/etc/pki/tls#' src/osdep/unix/Makefile
	perl -pi -e 's#SSLINCLUDE=\$\(SSLDIR\)/include#SSLINCLUDE=/usr/include/openssl#' src/osdep/unix/Makefile
	perl -pi -e 's#SSLLIB=\$\(SSLDIR\)/lib#SSLLIB=/usr/lib/openssl#' src/osdep/unix/Makefile
	if [ ${B64} -eq 0 ]; then
		make slx
	else
		make slx EXTRACFLAGS=-fPIC
	fi
fi

echo "Copying files to /usr/local/php-imap"
mkdir -p /usr/local/php-imap/include
mkdir -p /usr/local/php-imap/lib
chmod -R 077 /usr/local/php-imap
cp -f c-client/*.h /usr/local/php-imap/include/
cp -f c-client/*.c /usr/local/php-imap/lib/
cp -f c-client/c-client.a /usr/local/php-imap/lib/libc-client.a
cd ..
rm -rf ${FILENAME}

exit 0;
Run the script, then add to configure.php*:
Code:
--with-imap=/usr/local/php-imap \
--with-imap-ssl \
And rebuild PHP.
 

dmacleo

Verified User
Joined
Jun 21, 2012
Messages
641
so create a file (lets say imap.sh) containing this info and put it in directadmin/scripts and run it is all we need to do?
then add lines to php as needed of course.
if so would be nice to have that in the /scripts already, was surprised to see no imap upon install.
edit: should clarify, I mean no mention of imap. I know DA itself is imap capable.
sorry about phrasing that badly.
 
Last edited:

nridgway

Verified User
Joined
Jan 22, 2013
Messages
8
I've tried this but I am getting the following error:

./imap.sh: /bin/sh^M: bad interpreter: No such file or directory
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,789
Location
LT, EU
It looks like you have DOS characters in your file. Try opening the file with "nano -N", you should notice the difference.
 

GHvM

New member
Joined
Jun 25, 2013
Messages
1
Give it a try:
Code:
#!/bin/sh
# Script for PHP-IMAP installation. 0.1b
# Written by Martynas Bendorius (smtalk)

CWD=`pwd`
OS=`uname`

#Is it a 64-bit OS?
B64=0
	
B64COUNT=`uname -m | grep -c 64`
if [ "$B64COUNT" -eq 1 ]; then
	B64=1
	LD_LIBRARY_PATH=/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
	export LD_LIBRARY_PATH
fi

if [ ! -e /usr/include/krb5.h ] && [ -e /etc/redhat-release ]; then
	echo "Installing krb5-devel"
	yum -y install krb5-devel
fi

VERSION=2006k
URL="ftp://ftp.cac.washington.edu/imap/old/imap-${VERSION}.tar.Z"
FILENAME=imap-${VERSION}
TARBALL=${FILENAME}.tar.Z

echo "Downloading ${TARBALL}..."
wget -O ${TARBALL} ${URL}
tar xzf ${TARBALL}
cd ${FILENAME}

echo "Installing ${FILENAME}..."

if [ ${OS} = "FreeBSD" ]; then
	if [ ${B64} -eq 0 ]; then
		make bsf
	else
		make bsf EXTRACFLAGS=-fPIC
	fi
else
	perl -pi -e 's#SSLDIR=/usr/local/ssl#SSLDIR=/etc/pki/tls#' src/osdep/unix/Makefile
	perl -pi -e 's#SSLINCLUDE=\$\(SSLDIR\)/include#SSLINCLUDE=/usr/include/openssl#' src/osdep/unix/Makefile
	perl -pi -e 's#SSLLIB=\$\(SSLDIR\)/lib#SSLLIB=/usr/lib/openssl#' src/osdep/unix/Makefile
	if [ ${B64} -eq 0 ]; then
		make slx
	else
		make slx EXTRACFLAGS=-fPIC
	fi
fi

echo "Copying files to /usr/local/php-imap"
mkdir -p /usr/local/php-imap/include
mkdir -p /usr/local/php-imap/lib
chmod -R 077 /usr/local/php-imap
cp -f c-client/*.h /usr/local/php-imap/include/
cp -f c-client/*.c /usr/local/php-imap/lib/
cp -f c-client/c-client.a /usr/local/php-imap/lib/libc-client.a
cd ..
rm -rf ${FILENAME}

exit 0;
Run the script, then add to configure.php*:
Code:
--with-imap=/usr/local/php-imap \
--with-imap-ssl \
And rebuild PHP.
Why are you using version 2006k and not something newer?
I would like to use this solution, as stated it seems to work for people, but before I put this in production, I need to be sure I can use it.
All other solutions suggested by DirectAdmin do not work at all.

BTW: I am not using BSD or CentOS, but Ubuntu, so I need to rewrite it anyway.
 

jca

Verified User
Joined
Oct 31, 2006
Messages
237
Location
Allen, TX
I know you can change the reference of 2006k to the newest version and it will work.
 

3245

Verified User
Joined
Mar 28, 2013
Messages
34
hello
i do it
nano 1.sh
then put code on it, then ctrl + X
then sh 1.sh
but i see it freeze on Installing Imap-2006k...

it is normall? i must wait?

OS: centos 5.8 32bit

Thanks.
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,540
Last edited:

SeLLeRoNe

Super Moderator
Joined
Oct 9, 2004
Messages
6,793
Location
A Coruña, Spain
In smtalk script change VERSION to 2007f
and change URL to become:
URL="ftp://ftp.cac.washington.edu/imap/imap-${VERSION}.tar.Z"

Done, that will put 2007 version and it is compiled.. as it was the old one...

Regards
 

SeLLeRoNe

Super Moderator
Joined
Oct 9, 2004
Messages
6,793
Location
A Coruña, Spain
I suppose you does use custombuild as everyone else, so, where is the difference? If smtalk is trusteable with that why would not be with php-imap?

Also, that doesnt apply any modify and just do all the commands you would need to do manually, and, it still require you to use custom configure.php5 file to implement and recompile php with IMAP, in fact, that just prepare the require libraries in a specific folder, no server-wide messup, once you wanna remove that, just remove the dedicated folder.

Regards
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,540
Regarding smtalk script, first I get the error:

Code:
-bash: /root/setup-imap.sh: /bin/sh^M: bad interpreter: No such file or director
I fix that by adding a space in the first line between # and !/bin/sh so othat it becomes like this:

Code:
# !/bin/sh
Then I get this error:

Code:
[root@server~]# /root/setup-imap.sh
: command not found: line 4:
: command not found: line 7:
: command not found: line 10:
/root/setup-imap.sh: line 63: syntax error: unexpected end of file
[root@server~]#
@smtalk, would you bee so kind to just add the commands needed to manually do this on CentOS 6.4 64bit without using your script?

Edit: I removed the empty line space in line 4, 7 and 10, and now I only get this error:

Code:
[root@server~]# /root/setup-imap.sh
/root/setup-imap.sh: line 60: syntax error: unexpected end of file
[root@server~]#
 
Last edited:

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,540
I already is using a custom folder for php in custombuild, no problem. I only wanted more control by doing the comands manually, because the script is dynamic for many systems, and as I said I want more control by doing it manually.

However I have been trying to use the script, but as you can see in my previous post, I am not able to run it without errors.
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,789
Location
LT, EU
ditto, you must have been using MS Windows to save the script and upload it to the server. This way you have ^M characters in your file (open it with "nano -N" and you'll notice them). Please copy the code directly to the server, or use dos2unix tool to convert your current text file. That is very simple to do that (dos2unix /root/setup-imap.sh and that's it), you may use sed as an alternative to it, if you'd like to.
 
Top