php / php-src

The PHP Interpreter
https://www.php.net
Other
37.93k stars 7.72k forks source link

Cannot configure PHP from source to use the desired Kerberos library path #15333

Open ricky-rockstar opened 1 month ago

ricky-rockstar commented 1 month ago

Description

On Oracle Linux 8 I configure, make and make install my Kerberos library as follows

./configure --prefix=/kerberos-1.21.3 --enable-dns-for-realm

The above creates the folder /kerberos-1.21.3/lib with all my libraries in it.

I manually amend all /kerberos-1.21.3/lib/pkgconfig/*.pc files to contain the value libdir=/library

I then relocate an entire copy of the created library folder to my desired library location /library as follows:

cp /kerberos-1.21.3/lib/* /library

I "configure", "make" and "make install" PHP, with configure looking as follows:

env LD_LIBRARY_PATH=/library PKG_CONFIG=/usr/bin/pkg-config PKG_CONFIG_PATH=/library/pkgconfig KERBEROS_LIBS="-L/library -Wl,-rpath,/library" KERBEROS_CFLAGS="-I/kerberos-1.21.3/include" ./configure --prefix=/myphp --with-kerberos

Everything completes as normal.

As can be seen above, the environment I have set is:

This points all library information to the /library directory, and only the include header files directory to my original kerberos build location (via KERBEROS_CFLAGS and the /library/pkgconfig/*.pc files includedir= value)

All the documentation I have read says that with my configuration above, running ldd /myphp/bin/php should report as:

libkrb5.so.3 => /library/libkrb5.so.3

but when I run it, for libkrb5.so.3 I get the following:

libkrb5.so.3 => /kerberos-1.21.3/lib/libkrb5.so.3

Why am I getting the wrong -ie. original build - library location? I am literally tearing my hair out with this. Thanks

PHP Version

php 8.2.22

Operating System

Oracle Linux 8.10

petk commented 1 month ago

Hello, thanks for reporting issues you're having.

Is Kerberos here needed for the --with-openssl option or the --with-imap? Because otherwise, ideally you wouldn't need to link Kerberos libraries (krb5 and gssapi_krb5). They are mostly transitive linkages already resolved in the c-client or the OpenSSL package.

And the issue here is most likely related to the linked libraries of one of the .so files in the /library. If you check the ldd /library/*.so you'll most likely have some of those resolved to the original --prefix defined when configuring the Kerberos.

ricky-rockstar commented 1 month ago

Thank you! I'm building Kerberos primarily for OpenSSL which I'm also building from source and having no issues with. It is just Kerberos which is giving me problems. I am busy trying an alternative approach which I'm hoping will help by giving Kerberos the correct location and thus hopefully it's dependents, including PHP. I will update here either way.

Thank you again!

ricky-rockstar commented 1 month ago

Shew, I've made the changes that I believe will solve the kerberos issue, but now PHP configure is failing with

configure: error: Cannot find ldap.h

I have an open ldap build and it's --prefix folder is different from the --libdir folder

For Kerberos and others, this is no problem because there are specific environment variables which I can pass in order to identify the library folder (KERBEROS_LIBS) and the include folder (KERBEROS_CFLAGS) as in my original command above.

However using the PHP ./configure I can find no such equivalent for LDAP

I have tried running PHP configure with the following environment variables:

LDAP_LIBS=" -L/library/openldap -lldap -llber" 
LDAP_CFLAGS=" -I/openldap-2.6.7/include"
LDFLAGS=" -L/library/openldap" 
CPPFLAGS=" -I/openldap-2.6.7/include"

And ./configure switches

--with-ldap
--with-ldap-sas

both switches with identical values. These are the values I have tried:

no value at all                      (no directory specified)
=/openldap-2.6.7                (the openldap --prefix dir)
=/library/openldap              (the openldap --libdir dir)

And still I get the Cannot find ldap.h error.

(Just a side note in case relevant: I have run make clean )

So at this point my 2 questions are:

  1. Does PHP configure support an ldap build having --prefix folder independent from --libdir folder?
  2. If yes then how do I configure PHP to recognise it?

Any help would be greatly appreciated - thank you!

petk commented 1 month ago

LDAP unfortunately doesn't have the pkg-config added yet in PHP-8.2. It can be adjusted only with --with-ldap=DIR. :/

I'll check if we can squeeze the pkg-config into upcoming PHP-8.4.

ricky-rockstar commented 1 month ago

Thanks so much for getting back.

Ok my understanding for now is the following:

Assuming I build ldap using --prefix=/openldap-2.6.7 --libdir=/library

Then I must set the PHP config parameters as follows: --with-ldap=/openldap-2.6.7 --with-ldap-sasl=/openldap-2.6.7

Question 1: Please can you confirm the above is correct?

Question 2: Assuming the above is correct, then is there any way at all I can tell PHP configure to look for the ldap libraries in the /library folder? For example set some combination of LDFLAGS and CPPFLAGS (or other) environment values. And if so could you possibly provide me the parameters and values I should use to select /library?

Or am I stuck only being able to reference ldap libraries in /openldap-2.6.7/lib ?

Thank you again - this is tricky stuff for me and I really do appreciate your assistance!

petk commented 1 month ago

The --with-ldap=/openldap-2.6.7 is correct, yes, and the --with-ldap-sasl supports pkg-config and SASL_CFLAGS and SASL_LIBS variables.

I think what you can try is setting the EXTRA_LDFLAGS variable:

./configure EXTRA_LDFLAGS=-L/library

And it should find the library in that path. But this should be tested a bit if this works ok for this case.

ricky-rockstar commented 1 month ago

Thanks so much Peter! will try :)

ricky-rockstar commented 1 month ago

Hi Peter,

Unfortunately for an openldap library build having --prefix=/build/openldap-2.6.7 and --libdir=/webserver/resources/library/openldap

Even with the following included in PHP configure environment:

env  LDFLAGS=" -L/webserver/resources/library/openldap -Wl,-rpath,/webserver/resources/library/openldap" EXTRA_LDFLAGS=" -L/webserver/resources/library/openldap -Wl,-rpath,/webserver/resources/library/openldap" ... ./configure ...

I still get:

configure: error: Cannot find ldap libraries in /build/openldap-2.6.7/lib.
ERROR - configure: error: Cannot find ldap libraries in /build/openldap-2.6.7/lib. - Aborting deploy...!

The way I can find to work around this problem is to create the following symbolic link

ln -s  /webserver/resources/library/openldap /build/openldap-2.6.7/lib

Unless I'm doing something wrong above it indicates that the PHP current build only supports

<openldap --prefix>/lib 

for the openldap source library location.

:(