I need a standalone independent-from-system-libraries version of PHP to be able to distribute it as a .zip file containing binaries. Previously the .zip was containing libxml2.so.2, libpng12.so.0, php.ini and php executable. Recently I needed to add some functionalities and recompile the PHP. I did it with:
./configure \
--prefix=/home/user/php/out \
--libdir=. \
--enable-static=YES \
--enable-shared=NO \
--with-pdo_mysql \
--with-gd \
--with-mysql \
--enable-zip \
--enable-zend-multibyte \
--enable-cgi \
--enable-fastcgi \
--with-ldap=shared
make && make install
Then I took php from out/bin and libmysqlclient.so.16 from /usr/lib/. But the new php doesn't want to pick up the library. Once I run it I get the following error:
./php: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
libmysqlclient.so.16 and php are in the same directory. If i put libmysqlclient.so.16 to /usr/lib, php works fine.
Is there any additional option that I've forgotten about during compilation? Why isn't the "--libdir=." option working?
First, the directive is --with-libdir
not --libdir
. Second, I think it is relative to /usr
, so putting .
there means you need to put the shared libraries into /usr
.
If you have done any C coding with shared libraries, you must know about ld
. The easiest way to handle shared libraries path is to use ld
.
You can set the library path for the current (shell) session:
bash-4.1$ export LD_LIBRARY_PATH=/path/to/your/libs
You can also configure ld
to do it all the time:
bash-4.1$ echo /path/to/your/libs >> /etc/ld.so.conf
bash-4.1$ ldconfig