PDA

View Full Version : how-to: build php with proper imap support



sloop
10-15-2011, 07:29 PM
problem: on centos, the libc-client package is compiled with a low "FD_SETSIZE" limit (I assume 256). when adding imap support to php, compiling against the default libc-client RPMs, this will cause Apache to segfault if Apache has over 256 open file descriptors. All active apache logs count against this limit so its easy to hit on a shared hosting server.

solution: download latest imap c-client and compile from scratch:

download and extract


cd /usr/local
wget ftp://ftp.cac.washington.edu/imap/c-client.tar.Z
tar xvfz c-client.tar.Z
cd imap-2007f


edit source files

edit src/osdep/unix/os_art.c and src/osdep/unix/os_sv2.c in an editor,

find this:

#define FD_SETSIZE 256

change it to:

#define FD_SETSIZE 32768


openssl symlink

you should already have openssl and openssl-dev packages installed, but no /usr/local/ssl directory. run:



ln -s /usr/lib64/openssl/engines/ /usr/local/ssl
ln -s /usr/include/ /usr/local/ssl/include


compile imap c-client



make lnp SSLTYPE=unix EXTRACFLAGS=-fPIC


put files where php wants



mkdir lib
mkdir include
cp c-client/*.c lib/
cp c-client/*.h include/
cp c-client/c-client.a lib/libc-client.a


recompile php


cd /usr/local/directadmin/custombuild

if you don't already have a custom configure.php;



mkdir -p custom/ap2
cp configure/ap2/configure.php5 custom/ap2


add these lines to your custom/ap2/configure.php5 file:



--with-imap=/usr/local/imap-2007f \
--with-imap-ssl \



now run ./build php n

now your phpinfo() should show IMAP c-Client Version = 2007f

DirectAdmin Support
10-17-2011, 12:29 AM
Hello,

FYI, this guide has been around for a while as well:
http://help.directadmin.com/item.php?id=341

In any case, both guides have similarities.

John

sloop
10-17-2011, 06:55 AM
FYI, this guide has been around for a while as well:
http://help.directadmin.com/item.php?id=341


I was wondering why that guide has "--with-imap=/usr/lib/dovecot/imap" because I did not see a libc-client in /usr/lib/dovecot/imap, and the guide tells you to install the libc-client RPM anyway.

That guide doesn't address the FD_SETSIZE issue which was causing apache processes to segfault on a server with a few hundred sites when using php imap function.

mmx
10-18-2011, 11:40 AM
Hi sloop, thank you for this thread. I am a FreeBSD user, so I would like to add a few comments for those looking to compile IMAP and PHP on a FreeBSD 7.x and 8.x system (64-bit ok too!).

FreeBSD users can install the c-client libraries from ports, and compile php in DirectAdmin/custombuild without any problems.

You might get some errors when recompiling CURL or PHP, such as the following:


configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.


This means you are missing the cclient libraries. Just do the following to install them.



# cd /usr/ports/mail/cclient
# make install clean


I compiled with the default options (SSL and IPV6 support). I haven't applied the FD_SETSIZE fixes as sloop outlined above. I can look into this further if problems arise.

Afterwards, you can modify your custom configure.php5 configuration file and apply the following two lines at the end. Don't forget the backslashes (\)!



--with-imap=/usr/lib/dovecot/imap \
--with-imap-ssl


I also tried the following with success, but I rather let Dovecot manage my IMAP (I don't know if this makes a difference to be honest).



--with-imap \
--with-imap-ssl


I got this working with suPHP on a 8.2 machine, along with the latest OpenSSL from ports (1.0.0e).

Another note: if you are having problems with kerberos support in PHP 5.x, make sure you reference the directory in your configure.php5 like this (not fully tested, I compiled without kerberos support due to some other problems).



"--with-kerberos=/usr/local/include"

outpernet
10-28-2011, 12:58 PM
I tried this manual steps coz CentOS 6.0 here... and an error shows up in the middle, when I try to compile...:

cat osdepbas.c osdepckp.c osdeplog.c osdepssl.c > osdep.c
make[1]: *** No rule to make target `mail.h', needed by `osdep.o'. Stop.
make[1]: Leaving directory `/usr/local/imap-2007f/src/osdep/unix'
make: *** [lnp] Error 2







compile imap c-client



make lnp SSLTYPE=unix EXTRACFLAGS=-fPIC


put files where php wants



mkdir lib
mkdir include
cp c-client/*.c lib/
cp c-client/*.h include/
cp c-client/c-client.a lib/libc-client.a

soulshepard
03-03-2012, 11:40 PM
i am also trying to get a da centos 6 build working, as i also have imap ssl compiled in my previous centos 5 builds and i would assume this would be an easy task :(

anyone knows why c-client the /usr/lib/libc-client.a is not installed by default on centos 6?
i do see the /usr/lib/libc-client.so but this links on centos 5 to /usr/lib/libc-client.so.1 and the /usr/lib/libc-client.a links on centos 5 to c-client.a

i assume the modifications for the FD_SETSIZE seems logical but i never experienced any problems, who has changed this var in its custom builds?



(offtopic) for people that do want to automate this install you can use these sed commands to change the FD_SETSIZE values

/bin/sed -i 's/FD_SETSIZE\t256/FD_SETSIZE\t32768/' src/osdep/unix/os_art.c
/bin/sed -i 's/FD_SETSIZE\t256/FD_SETSIZE\t32768/' src/osdep/unix/os_sv2.c


i get a few warning messages when compiling



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Building in PARTIAL compliance with RFC 3501 security
+ requirements:
+ Compliant:
++ TLS/SSL encryption is supported
+ Non-compliant:
++ Unencrypted plaintext passwords are permitted
+
+ In order to rectify this problem, you MUST build with:
++ SSLTYPE=unix.nopwd
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Do you want to continue this build anyway? Type y or n please:


so should


make lnp SSLTYPE=unix EXTRACFLAGS=-fPIC


not be



make lnp SSLTYPE=unix.nopwd EXTRACFLAGS=-fPIC


as for the .nopwd would only allow clear text logins in an encrypted session.

what would be the default setting in the normal build!?

when compiling i see a few warning messages, and these give me allways an uncertain feeling as i dont know how it would impact later in the use or compile chain.



mh.c: In function âmh_pingâ:
mh.c:865: warning: passing argument 3 of scandir from incompatible pointer type
/usr/include/dirent.h:252: note: expected âint (*)(const struct dirent *)â but argument is of type âint (*)(struct dirent *)â
mh.c:865: warning: passing argument 4 of scandir from incompatible pointer type
/usr/include/dirent.h:252: note: expected âint (*)(const struct dirent **, const struct dirent **)â but argument is of type âint (*)(const void *, const void *)â
mh.c: In function âmh_appendâ:
mh.c:1131: warning: passing argument 3 of âscandirâ from incompatible pointer type
/usr/include/dirent.h:252: note: expected âint (*)(const struct dirent *)â but argument is of type âint (*)(struct dirent *)â
mh.c:1131: warning: passing argument 4 of âscandirâ from incompatible pointer type
/usr/include/dirent.h:252: note: expected âint (*)(const struct dirent **, const struct dirent **)â but argument is of type âint (*)(const void *, const void *)â


etc. with these warnings i allways want to not implement this, unfortunatly for centos 6 it seems the only way. :(
but i do hope the rpm repo would be fixed to include the /usr/lib/libc-client.a -> c-client.a

i dont understand why in the top procedure in the source folder you would put the .c and the .h files in the folders libs and includes?



mkdir lib
mkdir include
cp c-client/*.c lib/
cp c-client/*.h include/
cp c-client/c-client.a lib/libc-client.a


to install this lib would this not be enough?

edit: i understand now i overlooked the need to change your custom/ap2/configure.php5 with the folder to /usr/src/imap.. etc ;)




# install as lib
cp c-client/c-client.a /usr/lib/c-client.a
#link as lib
ln -s /usr/lib/c-client.a /usr/lib/libc-client.a



warning and disclaimer: i include here below my own version to auto install this, as i test this on my first centos 6 auto builds, becarefull when you just copy and paste things!! all read and understand first. thx




# install custom libc-client.a/c-client.a on a clean centos 6
#
# auto install TEST version
#
#source:http://www.directadmin.com/forum/showthread.php?t=41879&page=1
#problem: on centos, the libc-client package is compiled with a low "FD_SETSIZE" limit (I assume 256). when adding imap support to php, compiling against the default libc-client RPMs, this will cause Apache to segfault if Apache has over 256 open file descriptors. All active apache logs count against this limit so its easy to hit on a shared hosting server.
#
# dependency:
## pam-devel is an dependency for imapssl on a clean centos 6
#
yum install pam-devel -y
#
# perform c-client.a install
wget -O /usr/src/c-client.tar.Z ftp://ftp.cac.washington.edu/imap/c-client.tar.Z
tar -C /usr/src -xzvf /usr/src/c-client.tar.Z
/bin/sed -i 's/FD_SETSIZE\t256/FD_SETSIZE\t32768/' /usr/src/imap-2007f/src/osdep/unix/os_art.c
/bin/sed -i 's/FD_SETSIZE\t256/FD_SETSIZE\t32768/' /usr/src/imap-2007f/src/osdep/unix/os_sv2.c
ln -s /usr/lib64/openssl/engines/ /usr/local/ssl
ln -s /usr/include/ /usr/local/ssl/include
#.nopwd will allow only clear text logins in encrypted session, and only unix would allow this but give a warning
#make lnp SSLTYPE=unix.nopwd EXTRACFLAGS=-fPIC
# echo y = to accept the warning for insecure channels. probaly not the best thing but as this is public and it seems default i keep it in this post. please change as desired.
cd /usr/src/imap-2007f
echo y | make lnp SSLTYPE=unix EXTRACFLAGS=-fPIC
# install as lib
mkdir lib
mkdir include
cp c-client/*.c lib/
cp c-client/*.h include/
cp c-client/c-client.a lib/libc-client.a
# extra as systemwide lib
/bin/cp -f /usr/src/imap-2007f/c-client/c-client.a /usr/lib/c-client.a
#link as lib
ln -s /usr/lib/c-client.a /usr/lib/libc-client.a
#




# change custom apache for imapssl (and if you have allready the line --with-imap=/usr/lib/dovecot/imap \ in your custom configure.php5)
export getdatetimevar=`date +"%m%d%y%H%M%S"`
/bin/cp -f /usr/local/directadmin/custombuild/custom/ap2/configure.php5 /usr/local/directadmin/custombuild/custom/ap2/configure.php5-$getdatetimevar
sed -i 's/--with-imap=\/usr\/lib\/dovecot\/imap \\/--with-imap=\/usr\/src\/imap-2007f \\/' /usr/local/directadmin/custombuild/custom/ap2/configure.php5

turnersloane
05-15-2012, 11:27 AM
I am also trying to compile PHP with IMAP on CentOS 6. I have followed instructions of every post here and some from other websites. Finally got it to compile to a point where it doesn't complain about libc-client.a, but the compile eventually halts with these errors:
/usr/local/directadmin/custombuild/php-5.2.17/ext/imap/php_imap.c: In function 'zm_startup_imap':

/usr/local/directadmin/custombuild/php-5.2.17/ext/imap/php_imap.c:481: error: 'auth_gss' undeclared (first use in this function)

/usr/local/directadmin/custombuild/php-5.2.17/ext/imap/php_imap.c:481: error: (Each undeclared identifier is reported only once

/usr/local/directadmin/custombuild/php-5.2.17/ext/imap/php_imap.c:481: error: for each function it appears in.)

make: *** [ext/imap/php_imap.lo] Error 1

make: *** Waiting for unfinished jobs....

and when restarting httpd I get this error: invalid command php_admin_flag; apache is complaining about that flag in any vhost httpd.conf file. Any ideas?


UPDATE:
I used sloop's instructions above. Even with setting --with-imap=/to-the-path-where-libc-client.a resides, I still had compile errors. It seems PHP was looking elsewhere.

I verified that libc-client.a existed in /usr/local/imap-2007f/c-client and in /usr/local/imap-2007f/lib.

So....I created a symbolic link under /usr/lib for libc.client.a , set configure.php5 to

--with-imap=/usr/lib \
--with-imap-ssl

and recompiled with no problems. Thought I'd post this in case anyone else has the issue under CentOS 6.