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 (
-Wl,-rpath). If you only had
.a libraries it would work, but for
.so libraries what you need to specify is the
./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 (
This also takes care of adding
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
$ objdump -j dynamic -x ./libs/libphp5.so | fgrep RPATH
ldd will also confirm which libraries are loaded from where.
--with-jpeg-dir should be really be used for is to point at
/usr/local/ or some top-level directory, the directories
lib/, and possibly others are appended depending on what the compiler/linker needs.
You only need
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.)