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 downloaded and extracted the nginx source to ~/nginx-1.0.11, then downloaded PCRE 8.20 directly since the latest version of the Passenger installer can't download it automatically. I did the typical ./configure, make, sudo make install for PCRE which put it in /usr/local/lib by default. So far so good. Using passenger-install-nginx-module and specifying the source directory as /home/username/nginx-1.0.11 worked just fine.

When I ran a syntax check with /opt/nginx/sbin/nginx -t I was informed that libpcre.so.0 could not be located. I ran ldd against nginx and got the following:

linux-vdso.so.1 =>  (0x00007fff1dd7b000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fbfcde57000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x00007fbfcdc1e000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fbfcd909000)
libm.so.6 => /lib/libm.so.6 (0x00007fbfcd686000)
libpcre.so.0 => not found
    (truncated after this line)

Since nginx was able to find files in /usr/lib I recompiled PCRE with ./configure --prefix=/usr and now everything works great. My question is whether there's a smarter way to do this. Could I keep PCRE installed in the default /usr/local location and somehow tell the system or nginx to look in the lib directories there? Libraries are still a bit of a mystery to me.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

I can think of a few options...

/etc/ld.so.conf

You can add /usr/local/lib to the global list of library paths to be searched. Add it to the /etc/ld.so.conf file, then run ldconfig to update the cache. Personally, I'm not super comfortable with this option due to its global impact.

LD_LIBRARY_PATH

By adding /usr/local/lib to the LD_LIBRARY_PATH environmental variable, the system should be able to find it when nginx runs. You probably shouldn't set this permanently in your shell environment as it will have a similar global impact to modifying /etc/ld.so.conf. Instead you can test it out in an adhoc manner by prefixing your nginx command:

LD_LIBRARY_PATH=/usr/local/lib /opt/nginx/sbin/nginx -t

You could also set the variable in the init script for nginx.

options to configure

The configure script for nginx appears to have a flag that will allow you to pass extra options to ld. You could try running nginx's configure script with --with-ld-opt='-L/usr/local/lib'. I'm not sure if that would modify the library search path only at compile time, or whether it would impact run time as well. There could be other linker options that would do the trick, too. It's been a little while since I've had to mess with this stuff.

The configure script also appears to have a --with-pcre option for passing a path to the PCRE sources, but that seems to be used to statically link the library into nginx. That's probably not a good idea either.

I suggest doing a test build of nginx using --with-ld-opt='-L/usr/local/lib' (perhaps in a separate build directory, if you want to keep your original around). You could then check the compiled binary within the build directory with ldd like you did before to see if it made any difference.

share|improve this answer
    
Thank you, I found that /usr/local/lib was already included under /etc/ld.so.conf.d/ so I'm not sure why the lib didn't get picked up. I ran ldconfig and all was well after I removed libpcre from /usr/lib. –  Adam Dec 18 '11 at 1:40
    
To note, nginx built fine with PCRE support even without any compile-time flags. It was only the configuration test that failed before I ran ldconfig. –  Adam Dec 18 '11 at 1:41
add 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.