Freebsd – PHP Warning: PHP Startup: Unable to load dynamic library

freebsdlighttpdphp5

I have tried to run my script via cron, but it was not working…

*/1 * * * * /usr/local/bin/php -f /usr/local/www/maintain.php > /usr/local/www/php.log

So I decided to try to run this script from the command line in putty like this:

/usr/local/bin/php -f /usr/local/www/maintain.php > /usr/local/www/php.log

And then I've received the following warning/error message:

# /usr/local/bin/php /usr/local/www/maintain.php > /usr/local/www/php.log
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/20090626/libpcre.so' - Cannot open "/usr/local/lib/php/20090626/libpcre.so" in Unknown on line 0

But this script is running great, when I'm running it via www like http://my-url.com/maintain.php.

I'm using PHP 5~ with Lighttpd running od FreeBSD. Where is my problem?

Best Answer

Run this command (replacing /usr/bin/php with the path you're using to the PHP binary, in this case, /usr/local/bin/php):

# ldd /usr/bin/php
linux-gate.so.1 =>  (0x00932000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x00f16000)
libedit.so.0 => /usr/lib/libedit.so.0 (0x008dd000)
libncurses.so.5 => /lib/libncurses.so.5 (0x00791000)
libgmp.so.3 => /usr/lib/sse2/libgmp.so.3 (0x00de8000)
...

It allows you see precisely what shared libraries the binary depends on. I had this problem a while back with some cryptographic PHP library. The errors from PHP provided no useful information about why the script wasn't running, until I ran this command and could see what was missing. Whilst the error you are seeing complains about one specific library, there is a good chance that library depends on yet another one, which PHP is not telling you about in the error. ldd gives you this vital missing information.

Note I am running CentOS Linux here. For BSD, the ldd command might be called something else (I have never used BSD so can't comment on that).

Related Topic