Nginx – Using PCRE 8.20 with Nginx 1.0.11 and Passenger

nginxpcrephusion-passenger

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.

Best Answer

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.