PHP compilation - link to library

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I am compiling php 5.3.13 on my server. I want to create an autonome php5 folder. So prefix is:

/usr/local/php5

In this folder I have a lib folder, where I put all lib needed for php to be executed such as:

libk5crypto.so.3
libxml2.so.2
libjpeg.so.62 ....

Even if I compile with --with-jpeg-dir=/usr/local/php5/lib/, php binary is still looking for the file in /usr/lib64.

The only solution I found so far is to manually export LD_LIBRARY_PATH=/usr/local/php5/lib

I would like the same automatically at compile time. Is that possible?

profilepic.png
manpreet 2 years ago

There are two distinct linker paths, the compile time, and the run time.

I find autoconf (configure) is rarely set up to do the correct thing with alternate library locations, using --with-something= usually does not generate the correct linker flags (-R or -Wl,-rpath). If you only had .a libraries it would work, but for .so libraries what you need to specify is the RPATH:

export PHP_RPATHS=/usr/local/php5/lib
./configure [options as required] 

(In many cases just appending LDFLAGS to the configure command is used, but PHP's build process is slightly different.)

This effectively adds extra linker search paths to each binary, as if those paths were specified in LD_LIBRARY_PATH or your default linker config (/etc/ld.so.conf). This also takes care of adding -L/usr/local/php5/lib to LDFLAGS so that the compile-time and run-time use libraries are from the same directory (there's the potential for problems with mismatched versions in different locations, but you don't need to worry here).

Once built, you can check with:

 $ objdump -j dynamic -x ./sapi/cli/php | grep RPATH
 RPATH       /usr/local/php5/lib
 $ objdump -j dynamic -x ./libs/libphp5.so | fgrep RPATH
 RPATH       /usr/local/php5/lib

Running ldd will also confirm which libraries are loaded from where.

What --with-jpeg-dir should be really be used for is to point at /usr/local/ or some top-level directory, the directories include/lib/, and possibly others are appended depending on what the compiler/linker needs.

You only need --with-jpeg-dir if configure cannot find the installation, configure will automatically find it in /usr/local and other (possibly platform specific) "standard" places. In your case I think configure is finding libjpeg in a standard place, and silently disregarding the directive.

(Also, PHP 5.3.13 is no longer current, I suggest 5.3.21, the current version at this time.)


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.