1

We have an intranet site that has multiple PHP scripts which start using curl_init(). The other day there was an update for ArchLinux which messed with some of the dependencies of cURL (glibc). This caused the curl module to not properly load in PHP, that is, extension_loaded('curl') fails.

I get this error from Apache /var/http/error_log:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/curl.so' - /lib/libc.so.6: version `GLIBC_2.16' not found (required by /usr/lib/libcurl.so.4) in Unknown on line 0

  • The weird thing is we have another nearly identical script (on the same machine) that runs on PHP command line using curl_init() that runs via a cron job and PHP loads cURL properly during the execution of this script. That works perfectly fine.
  • cURL is configured to run in php.ini via extension=curl.so
  • If I check phpinfo(), I see '--with-curl=shared'. However it does not show the cURL info table. This tells me that the module isn't loading properly.
  • The curl.so file is in place at: /usr/lib/php/modules/curl.so
  • These cURL scripts also normally function properly, they are currently working great on another test machine.
  • This issue occurs on PHP 5.4.5

ldd /usr/lib/libcurl.so.4

linux-gate.so.1 (0xb7770000)
libssh2.so.1 => /lib/libssh2.so.1 (0xb76de000)
librt.so.1 => /lib/librt.so.1 (0xb76d5000)
libssl.so.1.0.0 => /lib/libssl.so.1.0.0 (0xb7673000)
libcrypto.so.1.0.0 => /lib/libcrypto.so.1.0.0 (0xb74ad000)
libz.so.1 => /lib/libz.so.1 (0xb7495000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb747a000)
libc.so.6 => /lib/libc.so.6 (0xb72d4000)
libdl.so.2 => /lib/libdl.so.2 (0xb72cf000)
/lib/ld-linux.so.2 (0xb7771000)

In my distro, the change they made was that /lib is now a symlink to /usr/lib: http://www.archlinux.org/news/the-lib-directory-becomes-a-symlink/

EDIT

I tried what DaveRandom suggested here...

[root http]# php -r " echo (file_exists('/usr/lib/php/modules/curl.so')) ? 'It exists.' : 'It doesn\'t e.'; "
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/json.so' - /usr/lib/php/modules/json.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  file_exists(): open_basedir restriction in effect. File(/usr/lib/php/modules/curl.so) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in Command line code on line 1

Warning: file_exists(): open_basedir restriction in effect. File(/usr/lib/php/modules/curl.so) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in Command line code on line 1
It doesn't exist.

It failed because it didn't allow access to that path via the ini, so I reconfigured it and tried again...

[root http]# php -r " echo (file_exists('/usr/lib/php/modules/curl.so')) ? 'It exists.' : 'It doesn\'t exist.'; "
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/json.so' - /usr/lib/php/modules/json.so: cannot open shared object file: No such file or directory in Unknown on line 0
It exists.

Freaky thing though is that JSON is actually working...

[root m]# php -r " echo (extension_loaded('json')) ? 'It is loaded' : 'It is not loaded'; "
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/json.so' - /usr/lib/php/modules/json.so: cannot open shared object file: No such file or directory in Unknown on line 0
It is loaded

I guess the question is, what would cause cURL to work on command line, the module file to be there, but fail to load the extension via Apache PHP.

Then on the other hand what would cause JSON to give a warning, but still actually load?

Anybody know what the heck this could be?

Thanks

11
  • You haven't chrooted Apache by any chance have you?
    – DaveRandom
    Commented Aug 7, 2012 at 15:16
  • That's jailing it right? No I don't believe so, but maybe it's like that normally in Arch? How would I tell? That command line script runs under /root via root though.
    – TheFrack
    Commented Aug 7, 2012 at 15:25
  • 1
    Well a simple file_exists('/usr/lib/php/modules/curl.so') in your PHP script will probably answer that question. If that returns true, PHP can definitely see the file it needs to load (in which case it's probably a problem with the SAPI the web server is using and a PHP recompile will most likely fix it). If that returns false, PHP can't even see the file, so that would be the place to start looking - why can't it see the file? chroot, it doesn't exist, etc etc. Although it may just be a bad glibc and that needs recompiling. That would be more fun, I suspect...
    – DaveRandom
    Commented Aug 7, 2012 at 15:48
  • 2
    To be honest you might find a better home for this question on ServerFault
    – DaveRandom
    Commented Aug 7, 2012 at 15:49
  • I made an edit at the end of my post, check it out. Apparently json is messed up as well. I'm not sure if that tells anything, but PHP can access the file. Should I manually just re-post on server fault or can it be moved?
    – TheFrack
    Commented Aug 7, 2012 at 16:36

2 Answers 2

4

Alrighty, I found a work around. It's basically just to downgrade from cURL 7.27.0-1 to 7.26.0-1, which kind of sux, but it works:

I think this issue was unique to ArchLinux, but this will fix it (if you're an ArchLinux user like me).

mkdir /tmp/pacman_build
cd /tmp/pacman_build
cp /var/cache/pacman/pkg/curl-7.26.0-1-`uname -m`.pkg.tar.xz .
tar -xJf curl-7.26.0-1-`uname -m`.pkg.tar.xz
LD_PRELOAD=/tmp/pacman_build/usr/lib/libcurl.so pacman -U /var/cache/pacman/pkg/curl-7.26.0-1-`uname -m`.pkg.tar.xz

Please note, this requires you to recently have version 7.26.0-1 of curl in your package manager cache. If this fails, check /var/cache/pacman/pkg for another version of curl. If you don't have one in there, you'll have to find one.

0

tl;dr: Make sure the PHP installation directory is in the system path.

I had this same problem. Apache's error log said something like "can't find module php_curl.dll", even though it was in the PHP ext/ directory and other extension DLLs in that directory seemed to be loading fine.

I wrote a PHP script with nothing but a call to phpinfo() and placed it in the document root. When I accessed that page through a browser (ie, via Apache), cURL didn't show up. But if I executed that same script from the command line, cURL did show up.

I think the Apache error message is misleading; I think what is really going on is that Apache can't find files that php_curl.dll depend on. These DLLs seem to be located in the PHP installation directory. The PHP directory was in my user path, but not the system path. That's why everything worked when I ran PHP as a user process.

Add the PHP installation directory to the system path, then re-start the Apache. Machine reboot does not seem necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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