Running Terser from a PHP script - a step-by-step guide

I have a PHP script that streamlines my development-to-production process. I am looking to utilize Terser for minifying the JavaScript files in my project. However, when I try to execute it using the php exec() function, I receive a result value of 1.

This indicates an undefined error. Unfortunately, I do not have further information about what went wrong, but I conducted the following tests:

  • The same Terser command runs successfully from a regular shell.
  • Executing exec('ls') displays the contents of the directory where the php script is located.
  • The Terser command is located in /usr/local/bin, and even after adding this path before the command, the result remains the same.
  • All users have read permission on the command and the rest of the Terser files.
  • All users have read & write permission on the directory containing the JS files and the target directory.

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 running this on Ubuntu 23.10

If anyone has any insights on how to troubleshoot and execute Terser from a PHP script, your input would be greatly appreciated.

Answer №1

After some investigation, it was discovered that Apache actually includes a set of useful libraries and PHP will try to utilize those first before seeking out the system libraries while running a command.

These libraries are older versions compared to what most updated systems have.

By clearing the LD_LIBRARY_PATH, PHP will no longer make the assumption that it should rely solely on what is included with Apache.

putenv('LD_LIBRARY_PATH=.');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error Handling with PHP's die() Command

There seems to be an issue that I am facing with the die() commands. On my website, I have a member registration page which includes a form. The form's action leads to another PHP script. However, when the form is submitted, instead of displaying an a ...

The functionality of Jquery AJAX is operational, however, the message being displayed appears to

Inside the file changename.php, there is a DIV element: <div id="resultDiv"></div> Within the same file, PHP code can be found: <?php include_once ('connect.php'); if(isset($_POST['name'])) { $postedname = $_POST[&ap ...

Enhance your WooCommerce shopping experience by incorporating a variety of personalized checkout fields organized into two distinct

I have implemented custom code to create unique checkout fields based on the number of products in a customer's cart. Each product requires 4 customized checkout fields, displayed in two columns side by side. The expected result is as follows: co ...

information not transferring between pages in the session

Every time a user logs into my website, a session and session data are supposed to be set. However, I am facing an issue where the session data is not being carried over from one page to another. Upon printing out the session array in the login script, it ...

Navigating through the outputs from a MySQL query

There is a specific functionality I am trying to achieve, although I may not have the exact terms to describe it. Let me explain what I need in detail. Initially, there is a variable named $id, which essentially represents $_GET['id']. For insta ...

PHP Quick Tip: How to effortlessly update a JSON array with new data

{ "messages": [ { "sender": "x", "message": "Placeholder", "date": "May 8, 2016 11:47:45 PM" } { "sender": "y", "mess ...

Issue with Ajax request in Laravel failing to function when ad blocker is active

While utilizing Laravel to send Ajax requests, everything functions properly on localhost. However, once I test it on the live server with an adblocker enabled, it fails to work. Once the adblocker is disabled, the functionality returns. domain.com/sponso ...

Reduce the count of products when the button is clicked

Hey there! I'm running a special promotion on my website with limited spots available at a reduced price. I'd love to have a real-time counter that shows the number of remaining spots, decreasing by one each time someone clicks the 'sign up& ...

Unpacking key-value pairs from a JSON array in PHP and restructuring the data

Looking for suggestions on how to transform the JSON structure shown below: $jsonArray = [{"Level":"77.2023%","Product":"Milk","Temperature":"4"}, {"Level":"399.2023%","Product":"Coffee","Temperature":"34"}, {"Level":"109.2023%","Product ...

Adding a new event using PHP with the Google Calendar API version 3

Currently, I am attempting to add an event using client libraries. Upon successfully passing oAuth, I encounter the following error: Fatal error: Call to a member function insert() on a non-object in zarzadzaj/kursy.php on line 17 My code snippet is as ...

Difficulty encountered while using MySQL column update button

I'm looking for assistance in updating my database using an SQL statement after a button is clicked on the website. I attempted something but it was unsuccessful. Could anyone provide guidance? Here's the code snippet: http://pastebin.com/D0S83Jg ...

What could be the reason for npm requesting a password?

Currently, I have a CentOS6.4 virtual box set up on Windows 8 using vagrant. In an attempt to install my project's dependencies, including proto, I ran into an unexpected issue. When running npm install proto, it asked me for a password. Why is npm su ...

Using Wordpress to convert seconds into a combination of minutes and seconds

I have a custom field named duration, with values represented in seconds. To display it within a post, I currently use: <?php echo get_post_meta($post->ID, 'key', true); ?> <?php echo get_post_meta($post->ID, 'duration' ...

Save files using file_put_contents and monitor the progress

When writing code to download a file and return the status (downloaded bytes), I utilize the file_put_contents method which works effectively. function downloadLink($link,$destination) { $ctx = stream_context_create(); stream_context_set_params($c ...

Discount on Shipping and Free Coupons at Magento

My shipping free rule is set up as follows: Applicable to all customer groups No coupon required Limited to 0 uses per customer Conditions: Cart total must be >= 100, and Shipping country must be NL, BE, or DE Free shipment available for matching items. ...

Issue with submitting forms in modal using Bootstrap

In the model box below, I am using it for login. When I click on either button, the page just reloads itself. Upon checking in Firebug, I found something like this: localhost\index.php?submit=Login <div class="modal fade" id="loginModal" tabindex= ...

PHP Inheritance failing to transfer data

I am struggling to pass values from a parent class. Despite trying basic examples, I can't seem to make it work. Your assistance would be greatly appreciated. class mother { public function __construct($db=""){ $this -> db = $ ...

How can we filter the input type file browse window to display only image files?

I'm trying to figure out how to filter the window popup so that it only shows image files when I click on the input type file. <input type="file" /> Any help would be greatly appreciated as I have been struggling to find a solution for this. ...

Mastering Dependency Injection for League Flysystem Integration

The goal is to develop a unique Reader class that functions as a wrapper for the League Flysystem documentation The purpose of the Reader is to provide a convenient way of reading all files in a directory, regardless of their physical form (local file or ...

Setting the application version for the Symfony WebProfiler is a simple process that can easily be

After reviewing this specific commit, it appears that there is now an option to set a custom application name and version for the WebProfiler. This raises the question of what the recommended method for doing so is? /** * Constructor. * * @param string ...