phplinuxterser

How to run Terser from PHP script?


I have PHP script that automates my dev-to-production proces. I want to use Terser to minify the JS in my project. But when I fire it with the php exec() function, I get a result value of 1.

This seems to indecate an undefined error. I have no further information what went wrong, but I did run the following tests:

stderr contains:

node: /opt/lampp/lib/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /lib/x86_64-linux-gnu/libnode.so.72)
node: /opt/lampp/lib/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /lib/x86_64-linux-gnu/libnode.so.72)
node: /opt/lampp/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /lib/x86_64-linux-gnu/libnode.so.72)
node: /opt/lampp/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /lib/x86_64-linux-gnu/libnode.so.72)
node: /opt/lampp/lib/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /lib/x86_64-linux-gnu/libnode.so.72)
node: /opt/lampp/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /lib/x86_64-linux-gnu/libicui18n.so.70)
node: /opt/lampp/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /lib/x86_64-linux-gnu/libicuuc.so.70)

I am working on Ubuntu 23.10

Does anyone know how to troubleshoot this and how to run Terser from a php script?


Solution

  • Got it: it turned out that apache comes with its own set of usefull libraries and that PHP tries to use those before it looks for the systems libraries when running a command.

    Those libs are older versions of the libs we all have on our updated systems.

    By clearing LD_LIBRARY_PATH, PHP no longer operates on the misconception that it should put too much trust in whatever comes with Apache.

    putenv('LD_LIBRARY_PATH=.');