TheFrack
TheFrack

Reputation: 2873

cURL 7.27.0-1 fails to load via Apache PHP, but works great on php command line

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

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

Upvotes: 1

Views: 1335

Answers (2)

flapjack
flapjack

Reputation: 87

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.

Upvotes: 0

TheFrack
TheFrack

Reputation: 2873

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.

Upvotes: 4

Related Questions