Compiling PHP w/ LDAP, IMAP, Support

Jeffreyb

Verified User
Joined
May 22, 2017
Messages
15
Hello,

To all whom find this topic:

If you want to add an php extension, and try to use this: https://help.directadmin.com/item.php?id=252
The variable: "ap2" stands for "apache 2", while if you use suphp, or fpm you need to change it respectively to suphp and fpm.... took me a while to figure out *sigh*

For IMAP: http://forum.directadmin.com/showthread.php?t=8271 works...

however when trying to install LDAP I fail miserably.

https://help.directadmin.com/item.php?id=341
should give an answer, buteeh... not working for me I'm afraid


So, the situation:
I first installed:
yum -y install openldap-devel cyrus-sasl-devel

but, due to a bug in PHP (or so), it cant find the so files. One solution would be to set --libdir=/usr/lib64, but that could cause problems. Thus, more commenly found is that people make a symlink from the lib64 to the lib dir.
ln -s /usr/lib64/libldap.so /usr/lib/libldap.so
ln -s /usr/lib64/libldap_r.so /usr/lib/libldap_r.so

Finally one needs to add the --with-ldap to the config file, and voila, it should all work


/usr/local/directadmin/custombuild/custom/fpm/configure.php71
Code:
#!/bin/sh
./configure \
        --prefix=/usr/local/php71 \
        --program-suffix=71 \
        --enable-fpm \
        --with-fpm-systemd \
        --with-config-file-scan-dir=/usr/local/php71/lib/php.conf.d \
        --with-curl=/usr/local/lib \
        --with-gd \
        --enable-gd-native-ttf \
        --with-gettext \
        --with-jpeg-dir=/usr/local/lib \
        --with-freetype-dir=/usr/local/lib \
        --with-libxml-dir=/usr/local/lib \
        --with-kerberos \
        --with-openssl --with-imap=/usr/local/imap-2007f --with-imap-ssl \
        --with-mcrypt \
        --with-mhash \
        --with-mysql-sock=/var/lib/mysql/mysql.sock \
        --with-mysqli=mysqlnd \
        --with-pcre-regex=/usr/local \
        --with-pdo-mysql=mysqlnd \
        --with-pear \
        --with-png-dir=/usr/local/lib \
        --with-xsl \
        --with-zlib \
        --with-zlib-dir=/usr/local/lib \
        --with-xmlrpc \
        --with-ldap=/usr \
        --with-ldap-sasl=/usr \
        --with-imap=/usr/local/imap-2007f \
        --with-imap-ssl \
        --enable-zip \
        --with-iconv=/usr/local \
        --enable-bcmath \
        --enable-calendar \
        --enable-ftp \
        --enable-sockets \
        --enable-soap \
        --enable-mbstring \
        --with-icu-dir=/usr/local/icu \
        --enable-intl
not really...
I tried

--with-ldap=/usr \
--with-ldap-sasl=/usr \
and
--with-ldap=/usr/lib64 \
--with-ldap-sasl=/usr/lib64 \
and
--with-ldap=/usr/local/lib \
--with-ldap-sasl=/usr/local/lib \

but what is right? I have honestly no idea what is means... So... PHP tells us the "dir" is the LDAP base install dir (http://php.net/manual/en/ldap.installation.php). So, where is the LDAP base install dir???
> rpm -ql ldap
package ldap is not installed

right...

> whereis ldap
ldap: /usr/include/ldap.h /usr/share/man/man3/ldap.3.gz

I'm stuck :| Anyone who can aid me on this quest?
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,255
Location
GMT +7.00
Hello,

In my case

Code:
--with-ldap \
--with-ldap-sasl \
were sufficient:

Code:
# php -i | egrep "^(ldap|sasl)" -i
ldap
LDAP Support => enabled
SASL Support => Enabled
ldap.max_links => Unlimited => Unlimited
Just make sure:

1.
Code:
rpm -qa | egrep "(ldap|sasl)"
returns list of packages, e.g.:

Code:
# rpm -qa | egrep "(ldap|sasl)"
cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64
openldap-devel-2.4.40-16.el6.x86_64
cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-2.1.23-15.el6_6.2.x86_64
openldap-2.4.40-16.el6.x86_64
2.
Code:
ls -1 /usr/lib64/libldap.so /usr/lib/libldap.so /usr/lib64/libldap_r.so /usr/lib/libldap_r.so
returns list of files, e.g.:


Code:
# ls -1 /usr/lib64/libldap.so /usr/lib/libldap.so /usr/lib64/libldap_r.so /usr/lib/libldap_r.so
/usr/lib64/libldap_r.so
/usr/lib64/libldap.so
/usr/lib/libldap_r.so
/usr/lib/libldap.so
3. make sure php compilation end without errors:

Code:
 php -v | grep ^PHP
check date and time at the line:


Code:
PHP 5.6.30 (cli) (built: Jun 15 2017 17:11:00)
 
Last edited:

Jeffreyb

Verified User
Joined
May 22, 2017
Messages
15
Hello zEitEr,

Thank you for your reply!

1.
Code:
# rpm -qa | egrep "(ldap|sasl)"
cyrus-sasl-2.1.26-20.el7_2.x86_64
openldap-devel-2.4.40-13.el7.x86_64
openldap-2.4.40-13.el7.x86_64
cyrus-sasl-lib-2.1.26-20.el7_2.x86_64
cyrus-sasl-devel-2.1.26-20.el7_2.x86_64
2.
Code:
# ls -1 /usr/lib64/libldap.so /usr/lib/libldap.so /usr/lib64/libldap_r.so /usr/lib/libldap_r.so
/usr/lib64/libldap_r.so
/usr/lib64/libldap.so
/usr/lib/libldap_r.so
/usr/lib/libldap.so
3.
Code:
# php -v | grep ^PHP
PHP 7.1.6 (cli) (built: Jun 13 2017 08:18:07) ( NTS )
(no errors, nor warnings, not sure how to test this for php 5.6, but I assume no errors/warnings as well)

Changed the lines to
Code:
        --with-ldap \
        --with-ldap-sasl \
results in:

Code:
...allot of text here..... -lcrypto -lcrypt  -o sapi/cli/php
/usr/local/imap-2007f/lib/libc-client.a(osdep.o): In function `ssl_onceonlyinit':
/usr/local/imap-2007f/c-client/osdep.c:337: warning: the use of `tmpnam' is dangerous, better use `mkstemp'
/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_strdup'
/usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
Perhaps it has something to do with php 7.1?
 

Jeffreyb

Verified User
Joined
May 22, 2017
Messages
15
It seems the problem is solved!

Code:
cd /usr/local/directadmin/custombuild/php-7.1.6/
make clean
This cleans up the php compiler/build, and... all the problems magically disappear........


@DA: Perhaps integrate "make clean" in custombuild? right before the php make command?
 

Jeffreyb

Verified User
Joined
May 22, 2017
Messages
15
It seems the problem is solved!
nope, not solved :| stupid me should have waited 20 min instead of 15 to post. Due to make clean, all packages had to be rebuild, which takes quite some time and thus making me think it went alright....
same error, same problem, no clue what to do.

p.s. Can someone please add an edit button to these forums :S?
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,255
Location
GMT +7.00
It build fine with PHP 7.1 on my end.

For Edit button you might need more posts.
 

Jeffreyb

Verified User
Joined
May 22, 2017
Messages
15
Somehow the problem has finally been resolved!

I removed the packages and reinstalled them (including pam-devel for IMAP), installed "openldap-devel cyrus-sasl-devel" first and then "pam-devel" but the problem remained.
Then I commented all -- lines in the config and added --disable all --with-ldap --with-ldap-sasl. Can't really remember if that worked tbh..

then I saw that I had --with-imap --with-imap-ssl twice in the below config(!)
So, I removed the 2nd instance of it, placed --with-ldap --with-ldap-sasl to the end of the file, and somehow it worked...
Code:
#!/bin/sh
./configure \
        --prefix=/usr/local/php71 \
        --program-suffix=71 \
        --enable-fpm \
        --with-fpm-systemd \
        --with-config-file-scan-dir=/usr/local/php71/lib/php.conf.d \
        --with-curl=/usr/local/lib \
        --with-gd \
        --enable-gd-native-ttf \
        --with-gettext \
        --with-jpeg-dir=/usr/local/lib \
        --with-freetype-dir=/usr/local/lib \
        --with-libxml-dir=/usr/local/lib \
        --with-kerberos \
        --with-openssl [B]--with-imap=/usr/local/imap-2007f --with-imap-ssl \[/B]
        --with-mcrypt \
        --with-mhash \
        --with-mysql-sock=/var/lib/mysql/mysql.sock \
        --with-mysqli=mysqlnd \
        --with-pcre-regex=/usr/local \
        --with-pdo-mysql=mysqlnd \
        --with-pear \
        --with-png-dir=/usr/local/lib \
        --with-xsl \
        --with-zlib \
        --with-zlib-dir=/usr/local/lib \
        --with-xmlrpc \
        --with-ldap \
        --with-ldap-sasl \
[B]        --with-imap=/usr/local/imap-2007f \
        --with-imap-ssl \
[/B]        --enable-zip \
        --with-iconv=/usr/local \
        --enable-bcmath \
        --enable-calendar \
        --enable-ftp \
        --enable-sockets \
        --enable-soap \
        --enable-mbstring \
        --with-icu-dir=/usr/local/icu \
        --enable-intl
So... what was the problem?
- The first time it worked, I had the two ldap lines at the end of the file. Placing them behind "--with-xmlrpc " again, still compiles with success.
- The first time with success, I had only "--with-openssl --with-imap=/usr/local/imap-2007f --with-imap-ssl ". I addedd the lines "--with-imap=/usr/local/imap-2007f \ --with-imap-ssl " after the 2 ldap lines (like in the first post), but it still compiles (well... why wouldn't it?)

thus, the success is due to:
- Installing "openldap-devel cyrus-sasl-devel" before "pam-devel" (unlikely)
- commenting all (yes, ALL!) "--" lines and adding "--disable all --with-ldap --with-ldap-sasl" to the 2nd line

or due to other magic... I have no idea!
 

Erulezz

Verified User
Joined
Sep 14, 2015
Messages
441
Location
Arnhem, NL
Code:
ls: cannot access /usr/lib/libldap.so: No such file or directory
ls: cannot access /usr/lib/libldap_r.so: No such file or directory
/usr/lib64/libldap_r.so
/usr/lib64/libldap.so
Now PHP still doesn't compile. Can I link these to /usr/lib or how?

Alrighty what worked for me was:

Code:
ln -s /usr/lib64/libldap.so /usr/lib/libldap.so
ln -s /usr/lib64/libldap_r.so /usr/lib/libldap_r.so
ln -s /usr/lib64/liblber.so /usr/lib/liblber.so
ln -s /usr/lib64/liblber-2.4.so.2 /usr/lib/liblber-2.4.so.2
Now PHP compiles without issues with LDAP :)
 
Last edited:
Top