Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Does /usr/local/lib/php/20090626/libpcre.so exist? Are you sure it's running from lighttpd and you don't just have error display off? –  Andy Feb 23 '12 at 16:07
    
It does exist, but in /usr/local/lib/libpcre.so. –  Cyclone Feb 23 '12 at 16:18
    
When I create a symlink in /usr/local/lib/php/20090626/ it does print another message: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'libpcre.so' in Unknown on line 0 –  Cyclone Feb 23 '12 at 16:23
1  
Nothing more than the file is required, try copying it instead. Alternatively update the reference in the file in /etc/php.d/X.ini, or it may be in your master php.ini –  Andy Feb 23 '12 at 17:04
    
Look for grep -r libpcre /usr/local/etc/php* and remove it. –  SaveTheRbtz Feb 24 '12 at 18:20
show 7 more comments

2 Answers 2

up vote 2 down vote accepted

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).

share|improve this answer
add comment

/usr/local/lib/libpcre.so is the C library.

Did you compile php yourself or from ports?

It looks like it was compiled with a custom PCRE library, because normally php should include pcre support.

share|improve this answer
    
From ports, php does include this library by default, while using lighttpd everything is fine, but when I run a PHP script from a command line, it throws this error... –  Cyclone Feb 28 '12 at 8:26
    
Shouldnt it be a comment? –  Cyclone Feb 28 '12 at 9:15
    
yes, but on that day i didn't have the privilege to add comments :). lighttpd uses php-cgi, since you are not reading any variables, you might try to use php-cgi from the commandline –  arved Feb 28 '12 at 9:40
    
I already did :/. Throws the same as normal php. –  Cyclone Feb 28 '12 at 9:45
    
FreeBSD ports don't install a php.ini per default. Some examples are installed as /usr/local/etc/php.ini-development and -production. Do you by chance have the php5-pcre port installed? it was deleted when php was updated to 5.3.2. See /usr/ports/UPDATING 20100409 entry –  arved Feb 28 '12 at 13:21
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.