Those "php code" tags make it look pretty enough to work.
None of the ugly black and white scripting.
I **think** you have the pairs in the search order paths interchanged.
As in, for the trusted system library paths:
/usr/lib:/lib rather than /lib:/usr/lib
Putting all the */usr/<whatever> before the */<whatever> allows the local install to "override" the system installed objects.
Same reasoning for */local/* those go before the "fixed" directories in the path to allow the local install to "override" the system installed objects.
There is probably a "spec" on this, somewhere, I don't know the reference off-hand.
Same for sbin
And invert the order of ld_library_path - same reasoning, the most specific first.
Hmm... Once you do that, you might not have to pre-load the "C" library.